From 748d28cc71f05a67407e36aa31c5de429d8ce8db Mon Sep 17 00:00:00 2001 From: Jose Manuel Delicado Date: Sat, 7 Oct 2017 18:26:21 +0200 Subject: [PATCH] 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 --- twython/api.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/twython/api.py b/twython/api.py index 2782168..577d6a6 100644 --- a/twython/api.py +++ b/twython/api.py @@ -140,7 +140,11 @@ class Twython(EndpointsMixin, object): params = params or {} func = getattr(self.client, method) - params, files = _transparent_params(params) + 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,15 +196,16 @@ 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: - raise TwythonError('Response was not valid JSON. \ - Unable to decode.') + if response.content!="": + raise TwythonError('Response was not valid JSON. \ + Unable to decode.') return content