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

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 8 views
8 views
Problem: Hi there! I have been working in Python for a while. I am trying to run following program: value = 4.0 for val in value: number = float(input("Enter a number: ")) if number == 0: print("Zero") elif number > 0: print("Positive") elif ... understand what is causing this error. I want to take input from user unless val becomes 4. Could anyone from here please help me solve this error?
asked Jan 15 Code Learner 5.5k points
0 votes
1 answer 4 views
4 views
Problem: So I'm trying to get the words in a four line text document sorted alphabetically and remove any words already in it, by Here's my code: # call text file fname = raw_input("Enter file name: ") # open file fh = open(fname) # create list fh = list(fh) #create empty ... () # check words in list for word in line: if word in lst: continue else: lst = lst.append(word) lst = lst.sort() print lst
asked Jan 11 Mashhoodch 6.7k points
0 votes
1 answer 18 views
18 views
On making a small program for math there returned an error "TypeError: 'NoneType' object is not subscriptable. Never before has been seen, this error, so no idea what it means. import math print("The format you should consider:") print str("value 1a")+str(" + ")+ ... /Nathan/Documents/Python/New thing", line 16, in <module> a = lista[1] - lista[0] TypeError: 'NoneType' object is not subscriptable
asked Oct 24, 2020 psandprop 2.4k points
2 votes
1 answer 57 views
57 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, 2020 Gavin 15.3k points
1 vote
1 answer 63 views
63 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, 2020 LizzyM 6.1k points
1 vote
1 answer 370 views
370 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, 2020 LizzyM 6.1k points
0 votes
1 answer 591 views
591 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
0 votes
1 answer 13 views
13 views
Problem: I am new to the world of programming . I recently started learning Python. I wrote following program: def check(list): for i in range(len(list)): list[i] = list[i+1] value = list[i] print(value) input_list = eval(input("Enter the items of list")) check( ... to replace the first item of the list with the second, and so on. I have no idea why this error is occurring. Can anybody help me?
asked Dec 27, 2020 Code Learner 5.5k points
0 votes
1 answer 28 views
28 views
Problem: Hello Programmers! I am new to the world of programming and I am working with arrays. I am trying to shuffle the elements of an array by using random.shuffle() method. I wrote the following program: import random Flowers = ["Lilies", "Roses", "Jasmine" ... ] TypeError: 'range' object does not support item assignment I have no idea what is causing this error. Any help regarding the issue??
asked Dec 24, 2020 Code Learner 5.5k points
0 votes
1 answer 69 views
69 views
Problem: I am running into this error for multiple variables, even handling missing values. For example: le = preprocessing.LabelEncoder() categorical = list(df.select_dtypes(include=['object']).columns.values) for cat in categorical: print(cat) df[cat].fillna('UNK', inplace=True) ... error results in: df['CRM do Médico'].isnull().sum() 0 Apart from nan values, what could be causing this error?
asked Dec 24, 2020 sasha 6.4k points