[英]Asyncore data processing with Python 3
我正在使用 asynchat 并尝试使用 python3。 收到此错误:
error: uncaptured python exception, closing channel <irc.IRC connected
at 0x9a5286c> (<class 'AttributeError'>:'str' object has no attribute
'more' [/usr/lib/python3.2/asyncore.py|write|89] [/usr/lib/python3.2
/asyncore.py|handle_write_event|462] [/usr/lib/python3.2asynchat.py|
handle_write|194] [/usr/lib/python3.2/asynchat.py|initiate_send|245])
我的代码在 Python 2.6.7 上运行良好。
请问有什么建议吗?
更新:我检查了我确实在使用 python3 的 asynchat。
~$ python3
Python 3.2 (r32:88445, Mar 25 2011, 19:28:28)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import asynchat
>>> asynchat
<module 'asynchat' from '/usr/lib/python3.2/asynchat.py'>
>>>
根据http://bugs.python.org/issue12523
实际上,错误在于 Python 3 在通过网络传输/接收数据时应该使用字节对象,而不是(unicode)字符串。 即用 b'\r\n' 替换 '\r\n' 等。
当然,错误信息应该不那么晦涩难懂。
该错误似乎在/usr/lib/python3.2/asynchat.py|initiate_send|245
中引发。
def initiate_send(self):
while self.producer_fifo and self.connected:
first = self.producer_fifo[0]
...
try:
data = buffer(first, 0, obs)
except TypeError:
data = first.more() <--- here
似乎有人在self.producer_fifo
中放置了一个字符串,而不是asyncchat.simple_producer
,这是async*.py
中唯一一个带有more()
方法的 class 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.