Skip to content

Commit

Permalink
Decode IMDB API output as utf-8
Browse files Browse the repository at this point in the history
I noticed that .movie sometimes generates a UnicodeDecodeError
exception, e.g. issuing '.movie gravity' produced:

  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
  151: ordinal not in range(128) (file "willie/modules/movie.py", line 26,
  in movie)

Adding an explicit 'utf-8' to u.decode() on the IMDB API result resolves
the issue for me.
  • Loading branch information
rameshdharan committed Mar 6, 2014
1 parent bb56dbf commit 66e1b1b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion willie/modules/movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def movie(bot, trigger):
word = word.replace(" ", "+")
uri = "http://www.imdbapi.com/?t=" + word
u = web.get(uri, 30)
data = json.loads(u.decode()) # data is a Dict containing all the information we need
data = json.loads(u.decode('utf-8')) # data is a Dict containing all the information we need
if data['Response'] == 'False':
if 'Error' in data:
message = '[MOVIE] %s' % data['Error']
Expand Down

0 comments on commit 66e1b1b

Please sign in to comment.