簡體   English   中英

使用 Python 3 進行異步數據處理

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM