私はこのasyncore.dispatcherモジュールを学び始めました。最初のサンプルプログラムを実行すると、以下のエラーが出ます。asyncore.dispatcher python module error
Pythonのバージョン2.6
asyncoreモジュールがインストールされ、ディスパッチャクラスは内部でもあります。何が問題なのでしょう!
エラー:
AttributeError: 'module' object has no attribute 'dispatcher'
コード例:
import asyncore, socket
class HTTPClient(asyncore.dispatcher):
def __init__(self, host, path):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, 80))
self.buffer = 'GET %s HTTP/1.0\r\n\r\n' % path
def handle_connect(self):
pass
def handle_close(self):
self.close()
def handle_read(self):
print self.recv(8192)
def writable(self):
return (len(self.buffer) > 0)
def handle_write(self):
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
client = HTTPClient('www.python.org', '/')
asyncore.loop()
エラーは何行発生していますか?完全なトレースバックを取得できますか? – aaronasterling
フルトレースバックをお願いします。 –
トレースバック(最新の呼び出しの最後): ":\ pythonの\ asyncore.py C"、3行目、 クラスでのHTTPClient(asyncore 輸入asyncore、ソケット ファイルで ファイル "asyncore.py"、ライン1、 .dispatcher): AttributeError: 'module'オブジェクトには属性 'dispatcher'がありません。 –