[英]Randomly NoneType object is not callable error
最近我在应用程序中遇到了这个问题:
在运行TypeError的文件“ app.pyc”的第205行的文件“ main.py”的第31行:“ NoneType”对象不可调用”
我的代码:
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位
它是有线的,因为它在大约1000次迭代后就出现了,没有任何先前的问题。 该应用程序扫描在线商店以获取当前价格。 首先,我认为我错过了某个地方,结果是None.encode('utf-8')
,但没有,并且“” .encode('utf-8')似乎有效。 而且,我无法在测试站点上重现此错误,只是有时会在努力工作约2500个产品时出现。 此错误的其他可能来源是什么?
>>> 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
在给定的行上,您将必须以某种方式将两个函数之一设置为None
。 您确定不是下一行,因为覆盖str
是一个相当常见的错误。
好的,解决了,有点奇怪,但是这个错误是由product['brand_name']
引起的,有时是BeautifulSoup.tag
(
这次标记),而不是我计划的BeautifulSoup.NavigableString
。 我仍然不明白为什么和wtf?
Anywat,非常感谢您的回复。 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.