2
我開始學習這個asyncore.dispatcher模塊,當我運行第一個示例程序時,它給出了下面的錯誤。asyncore.dispatcher python模塊錯誤
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 2011-01-26 05:50:00