mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-22 23:27:49 +01:00
properly handle utf-8 server response & identify json parsing errors
refs #134
This commit is contained in:
parent
a2d8ca3663
commit
79f29c4b9e
1 changed files with 5 additions and 1 deletions
|
@ -45,7 +45,11 @@ def _parse(json_data):
|
|||
Returns:
|
||||
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'):
|
||||
return data['description']
|
||||
|
|
Loading…
Reference in a new issue