Skip to content

Commit fdf3d31

Browse files
authored
rest: handle endpoints that don't output json
The /changes/<id>/revisions/current/patch?zip endpoint doesn't return json output but a binary data (the zipped contents of the change). The usual get() function raises a ValueError when faced with this. As a workaround provide a get_raw() function to allow callers to handle the decoding of data.
1 parent 89578cb commit fdf3d31

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pygerrit/rest/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ def get(self, endpoint, **kwargs):
117117
kwargs.update(self.kwargs.copy())
118118
response = requests.get(self.make_url(endpoint), **kwargs)
119119
return _decode_response(response)
120+
121+
def get_raw(self, endpoint, **kwargs):
122+
""" Send HTTP GET to the endpoint. Return raw result
123+
124+
:arg str endpoint: The endpoint to send to.
125+
126+
:returns:
127+
JSON decoded result.
128+
129+
:raises:
130+
requests.RequestException on timeout or connection error.
131+
132+
"""
133+
def get_raw(self, endpoint, **kwargs):
134+
kwargs.update(self.kwargs.copy())
135+
response = requests.get(self.make_url(endpoint), **kwargs)
136+
content = response.content.strip()
137+
response.raise_for_status()
138+
139+
return content
120140

121141
def put(self, endpoint, **kwargs):
122142
""" Send HTTP PUT to the endpoint.

0 commit comments

Comments
 (0)