1

I'm trying to use my script to automatically using google translate apis from russian to english. Here is the 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 for mytext, including unicode, utf-8, windows-1251 but it never works. Either the urllib.request complains of non-ascii characters or google returns an error code. Any idea if I need any codec?

1 Answer 1

4

Use

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

to quote your text

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.