I am trying acheive add / remove reviewer (gerrit set-reviewer), which requires using REST API from pygerrit
. I can add reviewers with no issues, using the rest.post()
methods, however rest.delete()
gives me ValueError: No JSON object could be decoded
in two cases:
First, in the below example reviewer (userID
) gets removed, but the API itself returns an JSON error.
In [64]: reviewer1 = "userID"
In [65]: rest.delete("/changes/" + changeid + "/reviewers/userID", data='{"message" : "%s"}' % "removed the reviewer" + reviewer1)
ERROR:root:Invalid json content:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-65-c972126a9f79> in <module>()
----> 1 rest.delete("/changes/" + changeid + "/reviewers/userID", data='{"message" : "%s"}' % "removed the reviewer" + reviewer1)
/home/user/.virtualenvs/testpy/local/lib/python2.7/site-packages/pygerrit/rest/__init__.pyc in delete(self, endpoint, **kwargs)
171 kwargs.update(self.kwargs.copy())
172 response = requests.delete(self.make_url(endpoint), **kwargs)
--> 173 return _decode_response(response)
174
175 def review(self, change_id, revision, review):
/home/user/.virtualenvs/testpy/local/lib/python2.7/site-packages/pygerrit/rest/__init__.pyc in _decode_response(response)
48 content = content[len(GERRIT_MAGIC_JSON_PREFIX):]
49 try:
---> 50 return json.loads(content)
51 except ValueError:
52 logging.error('Invalid json content: %s' % content)
/usr/lib/python2.7/json/__init__.pyc in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
337 parse_int is None and parse_float is None and
338 parse_constant is None and object_pairs_hook is None and not kw):
--> 339 return _default_decoder.decode(s)
340 if cls is None:
341 cls = JSONDecoder
/usr/lib/python2.7/json/decoder.pyc in decode(self, s, _w)
362
363 """
--> 364 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
365 end = _w(s, end).end()
366 if end != len(s):
/usr/lib/python2.7/json/decoder.pyc in raw_decode(self, s, idx)
380 obj, end = self.scan_once(s, idx)
381 except StopIteration:
--> 382 raise ValueError("No JSON object could be decoded")
383 return obj, end
ValueError: No JSON object could be decoded
Secondly, as per the documentation in 1, using rest.delete()
takes only two args, using the below method does not work and returns and error: 400 Client Error: Bad Request for url
. What am I missing ?
In [63]: rest.delete("/changes/" + changeid + "/reviewers/userID")
---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
<ipython-input-63-e71b8c78bcf1> in <module>()
----> 1 rest.delete("/changes/" + changeid + "/reviewers/userID")
/home/user/.virtualenvs/testpy/local/lib/python2.7/site-packages/pygerrit/rest/__init__.pyc in delete(self, endpoint, **kwargs)
171 kwargs.update(self.kwargs.copy())
172 response = requests.delete(self.make_url(endpoint), **kwargs)
--> 173 return _decode_response(response)
174
175 def review(self, change_id, revision, review):
/home/user/.virtualenvs/testpy/local/lib/python2.7/site-packages/pygerrit/rest/__init__.pyc in _decode_response(response)
44 content = response.content.strip()
45 logging.debug(content[:512])
---> 46 response.raise_for_status()
47 if content.startswith(GERRIT_MAGIC_JSON_PREFIX):
48 content = content[len(GERRIT_MAGIC_JSON_PREFIX):]
/home/user/.virtualenvs/testpy/local/lib/python2.7/site-packages/requests/models.pyc in raise_for_status(self)
882
883 if http_error_msg:
--> 884 raise HTTPError(http_error_msg, response=self)
885
886 def close(self):
HTTPError: 400 Client Error: Bad Request for url: https://git.review.org/gerrit/a/changes/CHANGEID/reviewers/userID