How to avoid API errors using except?
One of the errors I keep running into is this:
binance.exceptions.BinanceAPIException: APIError(code=-1000): An unknown error occured while processing the request.
I was just wondering if there is a way to pass this in a try statement? Here is what I use to pass timeout errors.
from requests.exceptions import Timeout
try:
#Insert code here
except Timeout:
pass
Are there any except functions like " except Timeout" for the other error codes that I could use?
you can just leave 'except' by itself
try: code except: pass
That binance.exceptions.BinanceAPIException is the name of the exception you're asking about, actually:
try:
stuff()
except binance.exceptions.BinanceAPIException as e:
print(e)
I try that and I only get "NameError: name 'binance' is not defined"
I manage this to work
try:
SellSta=client.get_order(symbol=Symb,orderId=SellOrderNum,recvWindow=Delay)
except Exception as e:
print ("Eror in line: {}".format(e))
print ("{}".format(e.status_code ))
print ("{}".format(e.response ))
print ("{}".format(e.code))
print ("{}".format(e.message))
print ("{}".format(e.request))
Now I'm trying to get different exceptions for differents errors
closing because this is unrelated to lib. rather it is related to how to handle errors.
for clarity on above:
@Chuox you should have imported binance like
from binance import exceptions.BinanceAPIException
closing because this is unrelated to lib. rather it is related to how to handle errors.
for clarity on above: @Chuox you should have imported binance like
from binance import exceptions.BinanceAPIException
@kimchirichie No bro...
from binance.exceptions import BinanceAPIException
try:
client.get_all_orders()
except BinanceAPIException as e:
print(e.status_code)
print(e.message)
But how can I specify particular error(code)? For instance I get occasionally binance.exceptions.BinanceAPIException: APIError(code=-2010) error. How can I handle it?
But how can I specify particular error(code)? For instance I get occasionally binance.exceptions.BinanceAPIException: APIError(code=-2010) error. How can I handle it?
@Shinizlc You can handle the error as follows:
try:
pass
except BinanceAPIException as err:
if err.code == -2010:
pass
else:
raise err
@lindomar-oliveira thank you a lot!