properly handle utf-8 server response & identify json parsing errors

refs #134
This commit is contained in:
Noam Meltzer 2015-12-26 00:34:26 +02:00
parent a2d8ca3663
commit 79f29c4b9e

View file

@ -45,7 +45,11 @@ def _parse(json_data):
Returns: Returns:
A JSON parsed as Python dict with results. A JSON parsed as Python dict with results.
""" """
data = json.loads(json_data.decode()) decoded_s = json_data.decode('utf-8')
try:
data = json.loads(decoded_s)
except ValueError:
raise TelegramError('Invalid server response; probably bad token')
if not data.get('ok') and data.get('description'): if not data.get('ok') and data.get('description'):
return data['description'] return data['description']