Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3270744
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:40:01+00:00 2026-05-17T18:40:01+00:00

I want to use Google Language Detection API in my app to detect language

  • 0

I want to use Google Language Detection API in my app to detect language of url parameter. For example user requests url

http://myapp.com/q?Это тест

and gets message “Russian”. I do it this way:

def get(self):                                            
        url = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q="+self.request.query                        
        try:
            data = json.loads(urllib2.urlopen(url).read())                
            self.response.out.write('<html><body>' + data["responseData"]["language"] +'</body></html>')                                  
        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])

but always get “English” as result because url is encoded in

http://myapp.com/q?%DD%F2%EE%20%F2%E5%F1%F2

I’ve tried urllib.quote , urllib.urlencode with no luck.

How I have to decode this url for Google Api?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:40:02+00:00Added an answer on May 17, 2026 at 6:40 pm

    Maybe urllib.unquote is what you are looking for:

    >>> from urllib import unquote
    >>> unquote("%DD%F2%EE%20%F2%E5%F1%F2")
    

    This gives you a string in which the characters are in whatever encoding that you’ve used in the URL. If you want to recode it to a different encoding (say, UTF-8), you have to create a unicode object first and then use the encode method of the unicode object to recode it:

    >>> from urllib import unquote, quote
    >>> import json, urllib2, pprint
    >>> decoded = unicode(unquote("%DD%F2%EE%20%F2%E5%F1%F2"), "windows-1251")
    >>> print decoded
    Это тест
    >>> recoded = decoded.encode("utf-8")
    

    At this point, we have an UTF-8 encoded string, but this is still not suitable to be passed on to the Google Language Detection API:

    >>> recoded
    '\xd0\xad\xd1\x82\xd0\xbe \xd1\x82\xd0\xb5\xd1\x81\xd1\x82'
    

    Since you want to include this string in a URL as a query argument, you have to encode it using urllib.quote:

    >>> url = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=%s" % quote(recoded)
    >>> data = json.loads(urllib2.urlopen(url).read())
    >>> pprint.pprint(data)
    {u'responseData': {u'confidence': 0.094033934,
                       u'isReliable': False,
                       u'language': u'ru'},
     u'responseDetails': None,
     u'responseStatus': 200}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new android app developer and i want to use google map
So I want to get a key to use Google API in Eclipse with
I want to use oscpack ( http://code.google.com/p/oscpack/ ) as a static library for my
i want to use this php-language-api i think it is great but with text
Greetings, I want to write a script that handles simple http requests from Google
I want to develop in the Go Language (go-lang) using Google App Engine to
my language is Arabic i want to use pathauto for clean URL but my
I want to use Google Mailhide to hide my email address from spam bots.
I want to use google guice to make properties available in all classes of
I want to use the google maps hand cursor in Python but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.