Unicode messages in reply cause exception
See original GitHub issueWhen 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:
- Created 8 years ago
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For Russian characters we are using following code
and all is working without any problems. why you are not use reply method?
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.