• Register
0 votes
1.2k views

Problem :

When I try to run the below code:

j=0
while j<5:
    j=j+1;
    try:
        MySellSta=client.get_order(symbol=MySymb,orderId=MySellOrderNum,recvWindow=MyDelay)
    except client.get_order as mye:
        print ("This is the error message!{}".format(j))
#End while

I got the following error: TypeError: catching classes that do not inherit from BaseException is not allowed

I kind of fix it with the below code:

j=0
while j<5:
    j=j+1;
    try:
        MySellSta=client.get_order(symbol=MySymb,orderId=MySellOrderNum,recvWindow=MDelay)
    except:
        print ("This is the error message!{}".format(i))
#End while

The result is that it ignores my error and go to my next while but I want to catch my error and print my error.

6 5 3
7,540 points

1 Answer

0 votes

Solution :

The above mentioned error usually occurs because in your exception clause you must indicate which exception you want to capture. An exception is your class that inherits directly or indirectly from your base class Exception.

Instead I have put the client.get_order where the python expected your name of the exception, but what you have put is the method of the object, and not the class that inherits from the Exception.

The solution is as below :

try:
    MySellSta=client.get_order(symbol=MySymb,orderId=MySellOrderNum,recvWindow=MyDelay)
except Exception as mye:
    if mye.code==-2013:
        print ("The Order does not exist.");
    elif mye.code==-2014:
        print ("The API-key format is invalid.");
    #End If

 

I hope the solution solves fixes your issues.

9 7 4
38,600 points

Related questions

2 votes
1 answer 41 views
41 views
Problem: What is TypeError: 'list' object is not callable error in python programming? Why does it happen? I was trying to working with a list in python. Suddenly, I got this error while I was trying run this below code list = [1, 2, 3] myrange = list(range(1, 10)) for num in list: if num in myrange: print(num, 'is between 1 and 10') Could any of you please shed some light on this?
asked Apr 7 Gavin 15.3k points
1 vote
1 answer 54 views
54 views
Problem: I am very noob in python programming language. To develope my skills I have been doing some coding prcatice. So, I wrote some which gives me error. The code I wrote is: for_test = "hiihihiiiiihhhi" print("The string you give is : " + str(for_test)) res = ... ')('%temp%', 'i') TypeError: 'str' object is not callable Why this error message is appearing can anyone explain.Please help me out.
asked Apr 7 LizzyM 6.1k points
1 vote
1 answer 233 views
233 views
Problem: When I run or compile this program import urllib2 import time import datetime HolaAndre = 'HUA','WALT','NOKA','CMG','EVAL','DARZ','SYM' def BackData(stock): try: print 'Still pulling',stock print str(datetime.datetime.fromtimestamp(time. ... BackData(eachStock) It shows me the following error main loop 'builtin_function_or_method' object is not iterable What is the problem please help me.
asked Apr 5 LizzyM 6.1k points
0 votes
1 answer 406 views
406 views
Problem : I am getting bellow error while I try to connect MySql database with Java using connector 8.0.11 java.sql.sqlnontransientconnectionexception: public key retrieval is not allowed
asked Oct 19, 2019 peterlaw 6.9k points