question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unicode messages in reply cause exception

See original GitHub issue

When i send a reply string with unicode characters (for example the swedish caracters åäö) i get the following exception.

Traceback (most recent call last):
  File "/home/grok/.virtualenvs/botdev/local/lib/python2.7/site-packages/mattermost_bot/dispatcher.py", line 66, in dispatch_msg
    func(Message(self._client, msg, self._pool), *args)
  File "/home/grok/code/fujitsu/matterbot/bot/cli.py", line 50, in quote_get
    message.reply(u"{}".format(data.get(str(id)), "No quote with ID: {0} exists in the database...".format(str(id))))
  File "/home/grok/.virtualenvs/botdev/local/lib/python2.7/site-packages/mattermost_bot/dispatcher.py", line 174, in reply
    self.send(self._gen_reply(text))
  File "/home/grok/.virtualenvs/botdev/local/lib/python2.7/site-packages/mattermost_bot/dispatcher.py", line 170, in _gen_reply
    return self._gen_at_message(text)
  File "/home/grok/.virtualenvs/botdev/local/lib/python2.7/site-packages/mattermost_bot/dispatcher.py", line 166, in _gen_at_message
    return '@{}: {}'.format(self.get_username(), text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe5' in position 1: ordinal not in range(128)

The simplest solution i found was to change this line https://github.com/LPgenerator/mattermost_bot/blob/master/mattermost_bot/dispatcher.py#L166 to be the following: return u'@{}: {}'.format(self.get_username(), text) where the new string will be unicode.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gotliumcommented, Feb 10, 2016

For Russian characters we are using following code

return '@{}: {}'.format(self.get_username(), 'Привет')

and all is working without any problems. why you are not use reply method?

0reactions
Grokzencommented, Feb 13, 2016

Sorted this out. It was the data that was read from a file that was the root cause of this problem. When that was fixed, it worked as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c++ - Exceptions with Unicode what() - Stack Overflow
One option is to use wcstombs() and friends to convert wstrings to strings, but you may have to convert the result of what()...
Read more >
Exception text could not be translated into unicode · Issue #681
Hi, there seems to be a problem with Npgsql.3.0.0-rc0002: An exception message containing umlaut could not be translated into unicode and so ...
Read more >
ArcSDESQLExecute error message contains unicode character
ArcSDESQLExecute(), it will return an error message with a unicode special character (see ArcSDESQLExecute_Error.gif). That unicode character in ...
Read more >
View topic - Unicode Parser Exception - MQSeries.net
Hi, I am using XMLNSC parser. In my input message i am getting some unicode characters and when the message enters into MB...
Read more >
Bug #1310397 “No response from rpc call when unicode in exceptio ...
is using unicode replacement text in a non-unicode string (py2x). This log and at least the other one in the file need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found