• Register
0 votes
2.6k 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

Please log in or register to answer this question.

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

0 votes
1 answer 21 views
21 views
Problem: I tried my best to solve this situation but it didnt work! any help! Typeerror: catching classes that do not inherit from baseexception is not allowed.
asked Mar 7 Wafa Abu Yousef 6.1k points
0 votes
1 answer 3 views
3 views
Problem: As I previously stated in my question, I am having difficulty learning. Could someone help assist me in completing my project?
asked Mar 30 tuhin1 48.4k points
0 votes
1 answer 84 views
84 views
Problem: What's wrong with the following code (under Python 2.7.1): class TestFailed(BaseException): def __new__(self, m): self.message = m def __str__(self): return self.message try: raise TestFailed('Oops') except TestFailed as x: print x
asked Feb 21 Mashhoodch 13k points
0 votes
1 answer 1 view
1 view
Question: All classes inherit from java.lang.Object, although extends Object is (generally) not written out anywhere. How is this possible?
asked 20 hours ago Atik03 5.9k points
0 votes
1 answer 7 views
7 views
Problem: How to fix this error: Typeerror: 'tuple' object is not callable
asked Mar 16 ummesalma 24.5k points
0 votes
1 answer 5 views
5 views
Problem: Could any of you please shed some light on this: python typeerror: 'list' object is not callable .
asked Mar 15 Wafa Abu Yousef 6.1k points
0 votes
1 answer 21 views
21 views
Problem: how to I Solve this: typeerror: a bytes-like object is required, not 'int' HELP! I need help understanding this: typeerror: a bytes-like object is required, not 'int' Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 8 Mashhoodch 13k points
0 votes
1 answer 11 views
11 views
Problem: How to I Solve this: python typeerror: 'nonetype' object is not iterable HELP! I need help understanding this: python typeerror: 'nonetype' object is not iterable Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 3 Mashhoodch 13k points
0 votes
1 answer 16 views
16 views
Problem: I am looking to make a loop so that for each element in the list, it will get broken down into each of it's characters. For example, say the number 137 was in the list then it would be turned into [1,3,7]. Then I want to add these numbers together (I ... it). However, I keep getting the error message TypeError: 'int' object is not iterable when I try and run this. What am I doing wrong?
asked Feb 23 Mashhoodch 13k points
0 votes
1 answer 57 views
57 views
Problem: What the traceback error is pointing out is the misuse of for statement: for i in Updt():. for in python 3 i "Python's for statement iterates? How function' object is not iterable. from getWords import getWords unique = [] def findUniqueWords(words): for word in words
asked Feb 15 Mashhoodch 13k points