I am trying to publish diff on ReviewBoard through their API. I managed to log in to the server and create a new message, but I could not correctly place the contents of the diff file.
I am new to writing such an application, but my goal is to take one step of the script:
- diff file (pre-commit) with svn repository,
- add a view request on ReviewBoard and post the diff from the current file,
Perhaps a later script might be part of the svn pre-commit binding.
My python attempt looks like this:
import urllib.request import urllib.parse import os.path ... login to the reviewboard server with urllib.request.HTTPBasicAuthHandler ... diff_path = '/path/to/file' diff_name = 'my.diff' diff_path = os.path.join(diff_path, diff_name) diff_val = open(diff_path,'r')
Using this code, I get a BAD REQUEST (400) error, in particular: "One or more fields had errors" (105).
I know that there are some libraries that can communicate with the ReviewBoard API. I also know that a post review exists. I would prefer not to distribute another python library to other developers, and the post-review seems less flexible when comparing files from multiple locations.
From the suggestion below, I will add a server response:
CREATING PASSWD MANAGER... CREATING PASSWD MANAGER... done CREATING PASSWD HANDLER... CREATING PASSWD HANDLER... done CREATING URL OPENER... CREATING URL OPENER... done LOADING DIFF... send: b'POST /api/review-requests/26/diffs/ HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 723\r\nHost: xxx.xxx.x.xxx\r\nContent-Type: application/x-www-form-urlencoded\r\nConnection: close\r\nUser-Agent: [empty no username+password] Python-urllib/3.2\r\n\r\ npath=--+SoMe+BoUnDaRy+++%...[the rest of my post] reply: 'HTTP/1.1 401 UNAUTHORIZED\r\n' header: Date header: Server header: Content-Language header: Expires header: Vary header: Cache-Control header: WWW-Authenticate header: Content-Length header: Last-Modified header: Connection header: Content-Type send: b'POST /api/review-requests/26/diffs/ HTTP/1.1\r\nAccept-Encoding: identity\r\nContent-Length: 723\r\nHost: xxx.xxx.x.xxx\r\nUser-Agent: Python-urllib/3.2\r\nConnection: close\r\nContent-Type: application/x-www-form-urlencoded\r\nAuthorization: Basic [with username+password]\r\n\r\npath=
At first glance, my hunch is that something is happening with my password handler. I'm not sure what is happening to him. Just in case, here's how I can generate my authentication:
manager_passwd = urllib.request.HTTPPasswordMgr() manager_passwd.add_password(...) handler_passwd = urllib.request.HTTPBasicAuthHandler(manager_passwd) opener = urllib.request.build_opener(handler_passwd)
Authentication seems to work. I tested it by creating a new review post. Therefore, when I send diff, authentication fails.