tdryer / hangups

the first third-party instant messaging client for Google Hangouts
https://hangups.readthedocs.io/
MIT License
1.71k stars 191 forks source link

Crash on Receiving Unicode (emoji) #286

Open Bobobalink opened 7 years ago

Bobobalink commented 7 years ago

Upon receiving an emoji in the open tab on the CLI interface, it crashes with this message:

Traceback (most recent call last):
  File "/usr/local/bin/hangups", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/hangups/ui/__main__.py", line 988, in main
    }, col_scheme, palette_colors, datetimefmt, notifier
  File "/usr/local/lib/python3.5/dist-packages/hangups/ui/__main__.py", line 98, in __init__
    loop.run_until_complete(self._client.connect())
  File "/usr/lib/python3.5/asyncio/base_events.py", line 387, in run_until_complete
    return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step
    result = coro.throw(exc)
  File "/usr/local/lib/python3.5/dist-packages/hangups/client.py", line 108, in connect
    yield from self._listen_future
  File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.5/dist-packages/hangups/channel.py", line 209, in listen
    yield from self._longpoll_request()
  File "/usr/local/lib/python3.5/dist-packages/hangups/channel.py", line 338, in _longpoll_request
    yield from self._on_push_data(chunk)
  File "/usr/local/lib/python3.5/dist-packages/hangups/channel.py", line 370, in _on_push_data
    yield from self.on_receive_array.fire(data_array)
  File "/usr/local/lib/python3.5/dist-packages/hangups/event.py", line 50, in fire
    yield from gen
  File "/usr/local/lib/python3.5/dist-packages/hangups/client.py", line 297, in _on_receive_array
    yield from self.on_state_update.fire(state_update)
  File "/usr/local/lib/python3.5/dist-packages/hangups/event.py", line 50, in fire
    yield from gen
  File "/usr/local/lib/python3.5/dist-packages/hangups/conversation.py", line 652, in _on_state_update
    state_update.event_notification.event
  File "/usr/local/lib/python3.5/dist-packages/hangups/conversation.py", line 668, in _on_event
    yield from self.on_event.fire(conv_event)
  File "/usr/local/lib/python3.5/dist-packages/hangups/event.py", line 48, in fire
    gen = observer(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/hangups/ui/__main__.py", line 187, in _on_event
    self._notifier.on_event(conv, conv_event)
  File "/usr/local/lib/python3.5/dist-packages/hangups/ui/notify.py", line 96, in on_event
    cmd, stderr=subprocess.STDOUT
  File "/usr/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/usr/lib/python3.5/subprocess.py", line 693, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1490, in _execute_child
    restore_signals, start_new_session, preexec_fn)
UnicodeEncodeError: 'ascii' codec can't encode character '\U0001f61e' in position 0: ordinal not in range(128)
Exception ignored in: <bound method ClientResponse.__del__ of <ClientResponse(https://0.client-channel.google.com/client-channel/channel/bind?CI=0&TYPE=xmlhttp&ctype=hangouts&VER=8&RID=rpc&t=1&SID=51163659D364A279&gsessionid=Q7Z5EEQCH5yJvuxMCYUHETCBlAGpjZgj) [200 OK]>
<_CIMultiDictProxy {'CACHE-CONTROL': 'no-cache, no-store, max-age=0, must-revalidate', 'PRAGMA': 'no-cache', 'EXPIRES': 'Mon, 01 Jan 1990 00:00:00 GMT', 'DATE': 'Wed, 21 Dec 2016 01:02:08 GMT', 'CONTENT-TYPE': 'text/plain; charset=utf-8', 'TRANSFER-ENCODING': 'chunked', 'X-CONTENT-TYPE-OPTIONS': 'nosniff', 'X-XSS-PROTECTION': '1; mode=block', 'SERVER': 'GSE', 'ALT-SVC': 'quic=":443"; ma=2592000; v="35,34"'}>
>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/aiohttp/client_reqrep.py", line 535, in __del__
  File "/usr/lib/python3.5/asyncio/base_events.py", line 1177, in call_exception_handler
  File "/usr/lib/python3.5/logging/__init__.py", line 1308, in error
  File "/usr/lib/python3.5/logging/__init__.py", line 1415, in _log
  File "/usr/lib/python3.5/logging/__init__.py", line 1425, in handle
  File "/usr/lib/python3.5/logging/__init__.py", line 1487, in callHandlers
  File "/usr/lib/python3.5/logging/__init__.py", line 855, in handle
  File "/usr/lib/python3.5/logging/__init__.py", line 1047, in emit
  File "/usr/lib/python3.5/logging/__init__.py", line 1037, in _open
NameError: name 'open' is not defined

If I relaunch hangups and open the tab again, the characters simply appear as question marks, as I assume they should in general. It only occurs if I receive a new emoji in the currently displayed chat.

tdryer commented 7 years ago

Looks like it's a problem with displaying the notification. What platform/distribution are you using?

Bobobalink commented 7 years ago

I'm using Ubuntu 16.04 with xfce4 and xfwm or whatever the default window manager is called. If the theme matters, I can hunt it down, but it's an arc derivative for high-dpi displays. I don't really remember where I found it.

tdryer commented 7 years ago

Can you try running these commands?

python3 -c "import sys; print(sys.getfilesystemencoding())"
python3 -c "import subprocess; print(subprocess.check_output(['echo', '\U0000263a']))"
Bobobalink commented 7 years ago

the first one returns "ascii" and the second crashes with the same error as above. (UnicodeEncodeError)

tdryer commented 7 years ago

Changing your system to use a utf-8 locale should fix the problem.

On the hangups side, one of these fixes could be implemented:

Bobobalink commented 7 years ago

That works, thanks! I hadn't even realized that my locale was messed up. Now to figure out how to display emoji in my terminal...