coleifer / irc

tinkering with a made-from-scratch irc library in python
http://irckit.readthedocs.org/
MIT License
179 stars 55 forks source link

It crashes when I try to send unicode data #11

Closed stewartpark closed 10 years ago

stewartpark commented 10 years ago
Traceback (most recent call last):
  File "app.py", line 42, in <module>
    run_bot(BlahBot, host, port, nick, ['#channel'])
  File "/Library/Python/2.7/site-packages/irc.py", line 326, in run_bot
    conn.enter_event_loop()
  File "/Library/Python/2.7/site-packages/irc.py", line 251, in enter_event_loop
    callback(**match.groupdict())
  File "/Library/Python/2.7/site-packages/irc.py", line 220, in handle_channel_message
    self.respond(result, channel=channel)
  File "/Library/Python/2.7/site-packages/irc.py", line 123, in respond
    self.send('PRIVMSG #%s :%s' % (channel.lstrip('#'), message))
  File "/Library/Python/2.7/site-packages/irc.py", line 76, in send
    self._sock_file.write('%s\r\n' % data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 316, in write
    data = str(data) # XXX Should really reject non-string non-buffers
UnicodeEncodeError: 'ascii' codec can't encode characters in position 18-19: ordinal not in range(128)
stewartpark commented 10 years ago

Oh, seems like Python doesn't allow to send unicode data without encoding it.

Send unicode data with xxx.encode('utf-8')

Problem solved.