I want to create simple application that detects language(using Google API) of phrase and send it to corresponded search engine. For example, if search query is in Russian then I need to redirect it to Yandex.ru in all other cases to Google.
That's how I do this:
def get(self):
decoded = unicode(unquote(self.request.query), "windows-1251")
text = decoded.encode("utf-8")
url = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q="+ quote(text)
try:
data = json.loads(urllib2.urlopen(url).read())
redirectUrl = "http://www.google.com/search?q=" + text
if data["responseData"]["language"] == 'ru':
redirectUrl = "http://yandex.ru/yandsearch?text=" + text
self.redirect(redirectUrl)
except urllib2.HTTPError, e:
self.response.out.write( "HTTP error: %d" % e.code )
except urllib2.URLError, e:
self.response.out.write( "Network error: %s" % e.reason.args[1])
When I request this url "http://findinrightplace.appspot.com/q?test query" it redirects to google but redirection to yandex doesn't work (http://findinrightplace.appspot.com/q?тестовый запрос).
What I'm doing wrong?