jaraco / irc

Full-featured Python IRC library for Python.
MIT License
392 stars 87 forks source link

unicode decode issue #19

Closed jaraco closed 8 years ago

jaraco commented 8 years ago

I have an irc bot which inherits from SingleServerIRCBot Because it also runs on different irc network's I 1st of all wrap it in:

**class BotWrapper(threading.Thread):
    def __init__(self,bot):
        self.bot = bot
        super(BotWrapper, self).__init__()
    def run(self):
        self.bot.start()****

I have been doing this for quite some time (this bot used the original python-irc)

I only post this since it is part of this traceback:

**Traceback (most recent call last):
  File "/usr/lib64/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "./bs.py", line 588, in run
    self.bot.start()
  File "/usr/lib64/python2.7/site-packages/irc/bot.py", line 260, in start
    super(SingleServerIRCBot, self).start()
  File "/usr/lib64/python2.7/site-packages/irc/client.py", line 1174, in start
    self.ircobj.process_forever()
  File "/usr/lib64/python2.7/site-packages/irc/client.py", line 264, in process_forever
    self.process_once(timeout)
  File "/usr/lib64/python2.7/site-packages/irc/client.py", line 245, in process_once
    self.process_data(i)
  File "/usr/lib64/python2.7/site-packages/irc/client.py", line 210, in process_data
    c.process_data()
  File "/usr/lib64/python2.7/site-packages/irc/client.py", line 554, in process_data
    for line in self.buffer:
  File "/usr/lib64/python2.7/site-packages/irc/buffer.py", line 84, in <genexpr>
    for line in super(DecodingLineBuffer, self).lines())
  File "/usr/lib64/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xf6 in position 53: invalid start byte
****

in the old python-irclib I would set DEBUG to true in the client.py. this upgraded irc lib seems to use logging but I cannot get it to write to a file

**logfp = logging.FileHandler('bsmithlog.log')
logfp.setLevel(logging.DEBUG)
irc.client.log.addHandler(logfp)****

jaraco commented 8 years ago

Hi. Sorry for the trouble.

Since version 3 of the library (see the changelog for details), the IRC library tries to provide a higher level interface, abstracting encoding and decoding of strings. By default, it assumes the server is using UTF-8 encoding.

If you want to restore the previous behavior, where the library just passes through the raw bytestream, there's a workaround indicated in the changelog. Let me know if that doesn't straighten things out for you or if you have additional questions.

As for the logging, I suspect that the logging level isn't set low enough to allow the messages to pass. Can you try:

irc.client.log.setLevel(logging.DEBUG)

in addition to what you've already specified?


Original comment by: Jason R. Coombs

jaraco commented 8 years ago

ahh ok.

Logging now works thankyou. I did lower the logging threshold (logging.DEBUG) but it seems to the filehander not the actual logger. This is mainly to catch a really annoying disconnect AND won't reconnect issue on a particular IRCD.

as to the utf-8 issue, for now I have added a very dirty try/except trap around each bot instance BUT with some additional prints while I get to the bottom of some of the new bits in this irc.


Original comment by: jonRB

jaraco commented 8 years ago

Glad I could help.


Original comment by: Jason R. Coombs