I'm trying to add try and except to my code but it does not work.
def _get_table_df(self, table):
l = module.send_command(name='Read', attributes={'type': table, 'method':'all', 'limit':'1', 'enable_custom':1})
so = BeautifulSoup(l.text,'xml')
columns = []
try:
for x in list(so.find(table).children):
columns.append(x.name)
df = pd.DataFrame(columns=columns)
except AttributeError:
return "no data"
return df
The error pointing to try line says
AttributeError: 'NoneType' object has no attribute 'children'
Related
def fetchAndUpdateAllOrderDetails(self, orders):
fyers = self.brokerHandle
orderBook = None
try:
orderBook = fyers.orderbook()
except Exception as e:
logging.error('%s Failed to fetch order book', self.broker)
return
logging.info('%s Order book length = %d', self.broker, len(orderBook))
numOrdersUpdated = 0
for bOrder in orderBook:
foundOrder = None
for order in orders:
if order.orderId == bOrder['orderBook']['id']:
foundOrder = order
break
if foundOrder != None:
def fetchAndUpdateAllTradeOrders():
allOrders = []
for trade in TradeManager.trades:
if trade.entryOrder != None:
allOrders.append(trade.entryOrder)
if trade.slOrder != None:
allOrders.append(trade.slOrder)
if trade.targetOrder != None:
allOrders.append(trade.targetOrder)
TradeManager.getOrderManager().fetchAndUpdateAllOrderDetails(orders = allOrders)
It returns the error:
Traceback (most recent call last):
File "d:\AlgoTraderFyers\src\trademgmt\TradeManager.py", line 76, in run
TradeManager.fetchAndUpdateAllTradeOrders()
File "d:\AlgoTraderFyers\src\trademgmt\TradeManager.py", line 227, in fetchAndUpdateAllTradeOrders
TradeManager.getOrderManager().fetchAndUpdateAllOrderDetails(orders = allOrders)
AttributeError: 'NoneType' object has no attribute 'fetchAndUpdateAllOrderDetails'
It was working with the other broker(zerodha). Pls help!
AttributeError: 'NoneType' object has no attribute 'fetchAndUpdateAllOrderDetails'
This means that the thing you are calling the fetchAndUpdateAllOrderDetails() function on is "None".
So in this case, the return value of TradeManager.getOrderManager() is None.
Are you returning anything from the getOrderManager() function?
I have problem at my code.
This is part of __init__:
file = np.loadtxt(file_path,delimiter = ",",skiprows=1)
header = np.loadtxt(file_path,delimiter = ",",dtype=str)
self.data = file
self.header = header[0]
This is part of a method:
def hello(self,col_name)
col = self.header.where[a == col_name]
return col
Then I wanted to check if I get the index of the header:
print (name.hello('hi'))
but got: "AttributeError: 'numpy.ndarray' object has no attribute 'where'"
I am trying to create a malware classifier and I am experiencing the error
AttributeError: 'Series' object has no attribute 'Id. Not sure of the error.
Traceback (most recent call last):
File"C:/Users/Afiqmatters/PycharmProjects/MajorProject/feature_extraction.py", line 23, in <module>
rids = [mids.loc[i].Id for i in rchoice]
File "C:\Users\Afiqmatters\Miniconda\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'Id'
Here is the codes I have up to the error.
rs = Random()
rs.seed(1)
trainLabels = pd.read_csv('trainLabels.csv')
#print trainLabels
fids = []
opd = pd.DataFrame()
for label in range(1,10):
mids = trainLabels[trainLabels.Class == label]
mids = mids.reset_index(drop=True)
#print mids
rchoice = [rs.randint(0, len(mids) - 1) for i in range(10)]
print len
#print rchoice
rids = [mids.loc[i].Id for i in rchoice]
The error happens at rids = [mids.loc[i].Id for i in rchoice] and I am not sure of the error.
A sample of what is stored in the trainLabels.csv
Id Class
0A32eTdBKayjCWhZqDOQ 2
mids.loc[i] in this context is a "Series" object which is detailed here
This object type does not have an attribute Series.Id, so that's why you're seeing this error.
Did you mean to call the built-in function id( ) on the object?
rids = [id(mids.loc[i]) for i in rchoice]
try:
res = self.browser.open('https://login.facebook.com/login.php?login_attempt=1',form_data)
response = res.read()
self.fbid = re.search('https://www.facebook.com/(.*)\?sk=info',response)
self.fbid = re.search('https://www.facebook.com/(.*)',self.fbid.group(1))
self.fbid = re.search('https://www.facebook.com/(.*)',self.fbid.group(1))
except urllib2.HTTPError,e :
print "****exception****inside login error code: %s" % (e.code)
res.close()
except urllib2.HTTPError,e :
print "****exception****inside login error code: %s" % (e.code)
#print " server Response Code: %s " % (res.code)
i got this
File "facebotv2.py", line 122, in login
self.fbid = re.search('https://www.facebook.com/(.*)',self.fbid.group(1))
AttributeError: 'NoneType' object has no attribute 'group'
self.fbid is None after your first regular expression search. This probably means that you didn't find a match. If you want to prevent the error, you can conditionally only continue searching the result of the initial search with if self.fbid != None
I am retrieving the last id from mssql and trying to incrementing it and storing the fie name with the id.. But I am getting "Attribute error : Nonetype object has no attribute 'id'"..The code and the error goes here :
import Tkinter,tkFileDialog
import shutil
import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=PAVAN;DATABASE=video;Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute("SELECT TOP 1 id FROM files ORDER BY id DESC ")
while 1:
row = cursor.fetchone()
if not row:
break
print row.id
cnxn.close()
middle = Tkinter.Tk()
def withdraw():
dirname = tkFileDialog.askopenfilename(parent=middle,initialdir="H:/",title='Please
select a file')
a="H:python(test)\py_"+row.id+".mp4"
b=shutil.copyfile(dirname,a)
if b!="":
print "Successfully Copied"
else:
print "Could not be copied"
B = Tkinter.Button(middle, text ="UPLOAD", command = withdraw)
middle.geometry("450x300+100+100")
middle.configure(background="black")
B.pack()
middle.mainloop()
The error I'm getting is:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\hp\Desktop\upload.py", line 20, in withdraw
a="H:python(test)\py_"+row.id+".mp4"
AttributeError: 'NoneType' object has no attribute 'id'
This occurs when the you try to get id Attribute from object which is of None type ,
Here is a case :
>> a = None
>> a.id
AttributeError: 'NoneType' object has no attribute 'id'
So it might be the case object row is of None type , and you are trying to print row.id
You may check for the type of row using :
type(**row**)
With Regards
Deepak