kurttheviking / simple-hipchat-py

Python client fo HipChat's v1 API
Other
85 stars 25 forks source link

doesn't handle unicode messages gracefully #17

Open cachrisman opened 8 years ago

cachrisman commented 8 years ago

If I try to use simple-hipchat-py to send a unicode message to a hipchat room I get the following error

  File "/app/utils.py", line 800, in send_hipchat_notification
    hipster.message_room(room_id, from_name, message)
  File "/app/.heroku/python/lib/python2.7/site-packages/hipchat/__init__.py", line 83, in message_room
    return self.method('rooms/message', 'POST', parameters)
  File "/app/.heroku/python/lib/python2.7/site-packages/hipchat/__init__.py", line 53, in method
    request_data = urlencode(parameters).encode('utf-8')
  File "/app/.heroku/python/lib/python2.7/urllib.py", line 1347, in urlencode
    v = quote_plus(str(v))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 20: ordinal not in range(128)

I had to install the unidecode library and put from unidecode import unidecode at the top of my file then do message = unidecode(message) before hipster.message_room(room_id, from_name, message) to get it working correctly.

Seems like simple-hipchat-py should handle unicode messages internally.

kurttheviking commented 8 years ago

@cachrisman thanks for pointing this out; I think this is an artifact of this libraries history in Python 2

I'll look into an enhancement to fix this; in the meantime, if you have a PR for it feel free to submit it