Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Avoid UnicodeDecodeErrors by using a different buffer #30

Open
jvperrin opened this issue Feb 7, 2018 · 0 comments
Open

Avoid UnicodeDecodeErrors by using a different buffer #30

jvperrin opened this issue Feb 7, 2018 · 0 comments

Comments

@jvperrin
Copy link
Member

jvperrin commented Feb 7, 2018

I believe we can do this by using a different buffer, like the following (taken from https://pypi.python.org/pypi/irc under "Decoding Input"):

from jaraco.stream import buffer
irc.client.ServerConnection.buffer_class = buffer.LenientDecodingLineBuffer

Otherwise, if invalid tokens are given, we get this error:

Exception in thread Thread-2:
Traceback (most recent call last):
 File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
   self.run()
 File "/usr/lib/python3.5/threading.py", line 862, in run 
   self._target(*self._args, **self._kwargs)
 File "/opt/ircbot/venv/lib/python3.5/site-packages/irc/bot.py", line 332, in start
   super(SingleServerIRCBot, self).start()
 File "/opt/ircbot/venv/lib/python3.5/site-packages/irc/client.py", line 1195, in start
   self.reactor.process_forever()
 File "/opt/ircbot/venv/lib/python3.5/site-packages/irc/client.py", line 273, in process_forever
   consume(infinite_call(one))
 File "/opt/ircbot/venv/lib/python3.5/site-packages/more_itertools/recipes.py", line 159, in consume
   deque(iterator, maxlen=0)
 File "/opt/ircbot/venv/lib/python3.5/site-packages/jaraco/itertools.py", line 386, in <genexpr>
   return (f() for _ in itertools.repeat(None))
 File "/opt/ircbot/venv/lib/python3.5/site-packages/irc/client.py", line 254, in process_once
   self.process_data(i)
 File "/opt/ircbot/venv/lib/python3.5/site-packages/irc/client.py", line 218, in process_data
   c.process_data()
 File "/opt/ircbot/venv/lib/python3.5/site-packages/irc/client.py", line 535, in process_data
   for line in self.buffer:
 File "/opt/ircbot/venv/lib/python3.5/site-packages/jaraco/stream/buffer.py", line 104, in lines
   self.handle_exception()
 File "/opt/ircbot/venv/lib/python3.5/site-packages/jaraco/stream/buffer.py", line 102, in lines
   yield line.decode(self.encoding, self.errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcc in position 511: unexpected end of data

Traceback (most recent call last):
 File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
   "__main__", mod_spec)
 File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
   exec(code, run_globals)
 File "/opt/ircbot/ircbot/ircbot.py", line 367, in <module>
   main()
 File "/opt/ircbot/ircbot/ircbot.py", line 361, in main
   raise RuntimeError('Thread exited: {}'.format(thread))
RuntimeError: Thread exited: <Thread(Thread-2, stopped daemon 140446527051520)>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant