Message140073
Asynchat push() function has a bug which prevents it from functioning.
This code worked fine with Python 2.
---------------------------------------------------------------
# https://github.com/jstoker/BasicBot
import asynchat,asyncore,socket
class asynchat_bot(asynchat.async_chat):
def __init__(self, host, port):
asynchat.async_chat.__init__(self)
self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
self.set_terminator('\r\n')
self.data=''
self.remote=(host,port)
self.connect(self.remote)
def handle_connect(self):
self.push('USER BasicBot 8 %s :BasicBot! http://github.com/jstoker/BasicBot\r\nNICK testbot\r\n' % self.remote[0])
def get_data(self):
r=self.data
self.data=''
return r
def collect_incoming_data(self, data):
self.data+=data
def found_terminator(self):
data=self.get_data()
if data[:4] == 'PING':
self.push('PONG %s' % data[5:]+'\r\n')
if '001' in data:
self.push('JOIN #bots\r\n')
if '~hi' in data:
self.push('PRIVMSG #bots :hi.\r\n')
if __name__ == '__main__':
asynchat_bot('127.0.0.1',16667)
asyncore.loop()
---------------------------------------------------------------
In Python 3 however, the exception follows:
---------------------------------------------------------------
~/tests/BasicBot$ python3 asynchat_bot.py
error: uncaptured python exception, closing channel <__main__.asynchat_bot connected at 0xb70078ac> (<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.2/asynchat.py|handle_write|194] [/usr/lib/python3.2/asynchat.py|initiate_send|245])
~/tests/BasicBot$ python3 -V
Python 3.2
~/tests/BasicBot$
---------------------------------------------------------------
A comment from Stackoverflow on why it happens:
---------------------------------------------------------------
The error seems to be raised in /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
Seems like somebody put a string in self.producer_fifo instead of an asyncchat.simple_producer, which is the only class in async*.py with a more() method. |
|
Date |
User |
Action |
Args |
2011-07-10 00:04:25 | Gryllida | set | recipients:
+ Gryllida |
2011-07-10 00:04:24 | Gryllida | set | messageid: <1310256264.97.0.142665013721.issue12523@psf.upfronthosting.co.za> |
2011-07-10 00:04:24 | Gryllida | link | issue12523 messages |
2011-07-10 00:04:23 | Gryllida | create | |
|