sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
5.98k stars 2.2k forks source link

Add default handling when key is not in json response #1197

Closed daviduhm closed 1 year ago

daviduhm commented 2 years ago

When Binance API is sending an unexpected response text, it sometimes doesn't have "code" or "msg" fields in the response and thus the following exception occurs:

File "/usr/local/lib/python3.8/dist-packages/binance/exceptions.py", line 14, in __init__ self.code = json_res['code'] KeyError: 'code'

This patch is to add a default handling when key is not present in JSON response.

sammchardy commented 1 year ago

Thanks @daviduhm