twython/api.py: JSON error is not raised if the response content is empty and the status code is not 204. If params is not a dictionary, _transparent_params is not called

This commit is contained in:
Jose Manuel Delicado 2017-10-07 18:26:21 +02:00
parent 12e6b34d1d
commit 748d28cc71

View file

@ -140,7 +140,11 @@ class Twython(EndpointsMixin, object):
params = params or {}
func = getattr(self.client, method)
if type(params) is dict:
params, files = _transparent_params(params)
else:
params = params
files = list()
requests_args = {}
for k, v in self.client_args.items():
@ -192,13 +196,14 @@ class Twython(EndpointsMixin, object):
error_message,
error_code=response.status_code,
retry_after=response.headers.get('X-Rate-Limit-Reset'))
content=""
try:
if response.status_code == 204:
content = response.content
else:
content = response.json()
except ValueError:
if response.content!="":
raise TwythonError('Response was not valid JSON. \
Unable to decode.')