api - using unicode in Google translate url from python script -


i'm trying use script automatically using google translate apis russian english. here code.

mytext = {some text in russian} url = 'https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='+ mytext +'&langpair=ru%7cen' request = urllib2.request(url, none, {'referer': 'http://www.mysite.org'}) 

now i've tried using various encodings mytext, including unicode, utf-8, windows-1251 never works. either urllib.request complains of non-ascii characters or google returns error code. idea if need codec?

use

url = 'https://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' \     + urllib2.quote(mytext) + '&langpair=ru%7cen' 

to quote text


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -