Reputation: 41
Recently I've got this problem in my application:
File "main.py", line 31, in File "app.pyc", line 205, in run TypeError: 'NoneType' object is not callable"
My code:
xml = EXML()
for pid, product in store.products.items():
xml.addRow()
xml.addCell((product['name']).encode('utf-8'), "String")
xml.addCell((product['symbol']).encode('utf-8'), "String")
xml.addCell((product['brand_name']).encode('utf-8'), "String") # line 205
xml.addCell(str(product['price']), "String")
Python 2.7 32-bit
It's wired, because this showed up after ~1000 iterations, with out any previus problem.
This application scans online store to get current prices.
Firstly I thought that somewhere I missed someting, and as result there is None.encode('utf-8')
, but no, and "".encode('utf-8') seems to work. Moreover, I can't reproduce this error on testing site, just sometimes shows up while hard-working with ~2500 products.
What are possible other sources of this error?
Upvotes: 2
Views: 1428
Reputation: 41
OK, solved, it's bit bizzare, but this error is caused by product['brand_name']
which is sometimes BeautifulSoup.tag
(
tag this time ) instead of BeautifulSoup.NavigableString
as I planned. I still don't understad why and wtf ?
Anywat, great thanks for response. :)
Upvotes: 0
Reputation: 107666
>>> None.encode
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'encode'
>>> None()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
On the given line you would have to set one of the two functions called to None
somehow. Are you sure it's not the next line, because overwriting str
is a rather common error.
Upvotes: 1