0

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
askb
  • 5,731
  • 25
  • 41

1 Answers1

0

The Gerrit delete-reviewer REST documentation shows that there's no JSON response for the DELETE endpoint, so I think your second try would be the correct one. Unfortunately I couldn't figure out why it didn't work. Let me point out some itens to check...

(1)

Why did you use:

rest.delete("/changes/" + changeid + "/reviewers/userID")

Instead of:

rest.delete("/changes/" + changeid + "/reviewers/" + userID)

(2)

It seems that this URL is wrong:

https://git.review.org/gerrit/a/changes/CHANGEID/reviewers/userID

The correct one should be:

https://git.review.org/a/changes/CHANGEID/reviewers/userID
  • I get "HTTPError: 400 Client Error: Bad Request for url" error with both ways! – askb Jan 09 '17 at 11:16
  • In [22]: query = ['status:open', 'owner:self', 'topic:some-topic', 'limit:100'] In [23]: changes = rest.get("/changes/?q=%s" % "%20".join(query)) The above code works with `https://git.review.org/gerrit/` so I am assuming that url should be correct. I am more interested in understanding why I get this error "ValueError: No JSON object could be decoded". Does delete() api work as expected in your case ? – askb Jan 09 '17 at 12:49
  • Sorry, I don't use python but I was able to remove a reviewer running the command: curl --request DELETE --netrc https://GERRIT-SERVER/a/changes/CHANGE/reviewers/USER – Marcelo Ávila de Oliveira Jan 09 '17 at 13:16