mchardysam / python-binance-chain

Binance Chain Exchange API python implementation for automated trading
http://python-binance-chain.rtfd.io
MIT License
303 stars 132 forks source link

Improper handling of 404 I suppose #2

Closed nandubatchu closed 5 years ago

nandubatchu commented 5 years ago

@sammchardy I am seeing error on querying with a fresh account with zero balance/transactions. I suppose you are handling 404s opaquely.

Traceback (most recent call last):
  File "##/binance_chain/http.py", line 228, in get_account
    return self._get(f"account/{address}")
  File "##/binance_chain/http.py", line 124, in _get
    return self._request('get', path, **kwargs)
  File "##/binance_chain/http.py", line 96, in _request
    return self._handle_response(response)
  File "##/binance_chain/http.py", line 105, in _handle_response
    raise BinanceChainAPIException(response, response.status_code)
binance_chain.exceptions.BinanceChainAPIException: APIError(code=0): Invalid JSON error message from Binance Chain: 
sammchardy commented 5 years ago

Yes you're right it's a 404 error with an empty body as the response from Binance Chain. What do you expect to receive? An exception should be raised, and if you catch this exception you would be able to access the status_code as a property of the exception. You can also access the response and request objects from the exception. See the following example:

try:
    client.get_account('nosuchaddress')
except BinanceChainAPIException as e:
    print(e.status_code)
    print(e.response)
    print(e.request)
nandubatchu commented 5 years ago

cool. Yes, using as you suggested. Thank you.

nacim31 commented 3 years ago

Hi @sammchardy ,@nandubatchu It seems that i have the same issue: File "/home/anaconda3/envs/crypto/lib/python3.5/site-packages/binance_chain/http.py", line 233 return self._get(f"account/{address}") ^ SyntaxError: invalid syntax But, i didn't understand how to fix it ! Thanks for your help