Skip to content

Commit

Permalink
[translate] Fix unicode in translate.py
Browse files Browse the repository at this point in the history
web returns a bytestring, we needed a unicodestring
  • Loading branch information
Elad Alfassa committed Apr 30, 2014
1 parent 84239d4 commit 83f36dd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def translate(text, in_lang='auto', out_lang='en'):
)
url = "http://translate.google.com/translate_a/t?{query}".format(query=query_string)
result = web.get(url, timeout=40, headers=headers)
if sys.version_info.major>=3:
if sys.version_info.major >= 3:
result = result.decode()
elif isinstance(result, str):
result = result.decode('utf-8')

while ',,' in result:
result = result.replace(',,', ',null,')
Expand Down

0 comments on commit 83f36dd

Please sign in to comment.