0

単純な IRC ボットを作成するというアイデアで遊んでいます。この目的のために書かれたさまざまな Python ソフトウェアがあり、さまざまな機能セットとさまざまな複雑さがあるようです。かなりユーザーフレンドリーなインターフェースを持っていると思われるこのパッケージを見つけて、インストールしました。

最初に、パッケージが Python 3 を考慮せずに作成されたように見えるという問題に遭遇しました。その上で 2to3 コンバーター ツールを実行したところ、その後パッケージをインポートできました。ただし、ドキュメントから例を複製しようとすると、質問のタイトルにエラーが表示されます。チャンネルの名前が削除された私のスクリプトは次のとおりです。

from ircutils import bot

class hambot (bot.SimpleBot):
    def on_channel_message (self, event):
        if event.message == 'go away hambot':
            self.quit('Goodbye.')

def main ():
    hb = hambot('hambot')
    hb.connect('irc.synirc.org', channel = '(channel name removed)')
    hb.start()

if __name__ == '__main__': main()

実行しようとすると、次の結果が得られます。asynchat.py最初の例外は、IRCUtils パッケージの一部ではなく、Python 自体の一部のように見えるというスクリプトのみを参照しているため、何が問題なのか少しわかりません。

Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hambot
>>> hambot.main()
Traceback (most recent call last):
  File "C:\Python32\lib\asynchat.py", line 243, in initiate_send
    data = buffer(first, 0, obs)
  File "C:\Python32\lib\asynchat.py", line 56, in buffer
    memoryview(obj)
TypeError: cannot make memory view because object does not have the buffer inter
face

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Docs\programs\python\hambot\hambot.py", line 11, in main
    hb.start()
  File "C:\Python32\lib\site-packages\ircutils\client.py", line 271, in start
    self.conn.start()
  File "C:\Python32\lib\site-packages\ircutils\connection.py", line 115, in star
t
    asyncore.loop(map=self._map)
  File "C:\Python32\lib\asyncore.py", line 216, in loop
    poll_fun(timeout, map)
  File "C:\Python32\lib\asyncore.py", line 162, in poll
    write(obj)
  File "C:\Python32\lib\asyncore.py", line 95, in write
    obj.handle_error()
  File "C:\Python32\lib\asyncore.py", line 91, in write
    obj.handle_write_event()
  File "C:\Python32\lib\asyncore.py", line 466, in handle_write_event
    self.handle_write()
  File "C:\Python32\lib\asynchat.py", line 194, in handle_write
    self.initiate_send()
  File "C:\Python32\lib\asynchat.py", line 245, in initiate_send
    data = first.more()
AttributeError: 'str' object has no attribute 'more'
>>>

このエラー メッセージに関連する StackOverflow には既に 1 つの質問がありますが、受け入れられた回答では、「gevent」というパッケージに関連していると述べられています。これに関係するとは思わない。

4

1 に答える 1

0

この問題は、Python 3 で文字列が機能する方法が変更されたために発生します。次のバグが関連している可能性があります: http://bugs.python.org/issue12523

IRCUtils ライブラリは、次のように動作するように作成できます。2to3 スクリプトの実行に加えて、次の変更を に加えますconnection.py

Line 31: change from
    self.set_terminator("\r\n")
to
    self.set_terminator(b"\r\n")

Line 63: change from
    data = "".join(self.incoming)
to
    data = "".join([x.decode('utf8', 'replace') for x in self.incoming])

Line 96: change from
    self.push("%s %s\r\n" % (command.upper(), " ".join(params)))
to
    self.push(bytes("%s %s\r\n" % (command.upper(), " ".join(params)), 'utf8'))
于 2012-12-04T12:04:54.853 に答える