开发者

Asyncore data processing with Python 3

I'm using asynchat and trying to use python3. getting this error:

    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])

My code worked fine with Python 2.6.7.

Suggestions please?

UPDATE: I checked that I'm indeed using python3's 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'>
    &g开发者_如何学JAVAt;>> 


Per http://bugs.python.org/issue12523

Actually, the error is that in Python 3 you should use bytes objects when transmitting/receiving data over the network, not (unicode) strings. That is, replace '\r\n' with b'\r\n', etc.

Of course, the error message should be made less obscure.


The error seems to be raised in /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 

Seems like somebody put a string in self.producer_fifo instead of an asyncchat.simple_producer, which is the only class in async*.py with a more() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜