ProgVal/Limnoria — Issue #318: UnicodeEncodeError in Google Calc
Author: Hoaas
Created: 2012-03-08 14:11:07+00:00
State: open

Calling Google Calc where the answer contains a space results in the error below.
Have not seen anyone else have this problem. Might perhaps be depending on locales?

I made the bot reply the full json:
< Hoaas > !calc 1+1
< Bunisher > {u'icc': False, u'rhs': u'2', u'lhs': u'1 + 1', u'error': u''}
< Bunisher > 1 + 1 = 2

< Hoaas > !calc 1000000+1
< Bunisher > {u'icc': False, u'rhs': u'1\xa0000\xa0001', u'lhs': u'1\xa0000\xa0000 + 1', u'error': u''}
< Bunisher > An error has occurred and has been logged. Check the logs for more informations.

Fixed this by changing def calc() (line 354):
```
< irc.reply("%s = %s" % (js['lhs'], js['rhs'],))
> irc.reply("%s = %s" % (js['lhs'].encode('utf8'), js['rhs'].encode('utf8'),))
```

Error from the log:

ERROR 2012-03-08T12:15:21 supybot Uncaught exception in ['calc'].
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/supybot/callbacks.py", line 1210, in _callCommand
self.callCommand(command, irc, msg, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/supybot/utils/python.py", line 86, in g
f(self, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/supybot/callbacks.py", line 1196, in callCommand
method(irc, msg, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/supybot/commands.py", line 1013, in newf
f(self, irc, msg, args, *state.args, **state.kwargs)
File "/usr/local/lib/python2.6/dist-packages/supybot/plugins/Google/plugin.py", line 354, in calc
irc.reply("%s = %s" % (js['lhs'], js['rhs'],))
File "/usr/local/lib/python2.6/dist-packages/supybot/callbacks.py", line 833, in reply
s = str(s) # Allow non-string esses.
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 22: ordinal not in range(128)
ERROR 2012-03-08T12:15:21 supybot Exception id: 0x54b91