Skip to content

Commit

Permalink
fix JSONDecodeError missing for py2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
boogheta committed Aug 25, 2022
1 parent ab3d73c commit c23229d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion twitter/api.py
Expand Up @@ -40,6 +40,11 @@
except ImportError:
import simplejson as json

try:
from json.decoder import JSONDecodeError
except ImportError:
JSONDecodeError = ValueError


class _DEFAULT(object):
pass
Expand Down Expand Up @@ -391,7 +396,7 @@ def _handle_response(self, req, uri, arg_data, _timeout=None):
elif "json" == self.format:
try:
res = json.loads(data.decode('utf8'))
except json.decoder.JSONDecodeError as e:
except JSONDecodeError as e:
# it seems like the data received was incomplete
# and we should catch it to allow retries
raise TwitterError("Incomplete JSON data collected for %s (%s): %s)" % (uri, arg_data, e))
Expand Down

0 comments on commit c23229d

Please sign in to comment.