【问题标题】:Asyncore data processing with Python 3使用 Python 3 进行异步数据处理
【发布时间】:2011-07-08 12:48:31
【问题描述】:

我正在使用 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'>
    >>> 

【问题讨论】:

  • 您确定问题出在这个 sn-p 上吗?错误显示'str' object has no attribute 'more'。检查你是否没有在某处打电话给more
  • @Senthess -- 是的,我很确定问题是异步的,因为 1) 错误消息没有提到我的任何文件; 2) 在我的文件中搜索“更多”不会返回任何相关内容(仅许可块中的单词)。

标签: python exception python-3.x attributeerror


【解决方案1】:

http://bugs.python.org/issue12523

实际上,错误在于,在 Python 3 中,您应该在通过网络传输/接收数据时使用字节对象,而不是(unicode)字符串。 即用b'\r\n'等替换'\r\n'等

当然,错误信息应该不那么晦涩。

【讨论】:

    【解决方案2】:

    /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() 方法的类。

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多