最近我在我的应用程序中遇到了这个问题:
File "main.py", line 31, in File "app.pyc", line 205, in run TypeError: 'NoneType' object is not callable"
我的代码:
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 是一个相当常见的错误。
