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 6925471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:47:37+00:00 2026-05-27T10:47:37+00:00

I do geocoding with python and I think I need to encode the variable

  • 0

I do geocoding with python and I think I need to encode the variable region with urllencode so that it works with content that has whitespace and other special characters:

url = urllib.urlencode('http://maps.googleapis.com/maps/api/geocode/json?address='+region+'&sensor=false')
logging.info('url:'+url)
result = urlfetch.fetch(url)

It generates an error log when the variable region contains a whitespace

Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~montaoproject/pricehandling.355268396595012751/in.py", line 153, in get
    url = urllib.urlencode('http://maps.googleapis.com/maps/api/geocode/json?address='+region+'&sensor=false')
  File "/base/python27_runtime/python27_dist/lib/python2.7/urllib.py", line 1275, in urlencode
    raise TypeError
TypeError: not a valid non-string sequence or mapping object

The background is another question I asked where I had I problem that I’m troublehhotting to be that the code works but not for regions that are two or more words ie names with whitespaces.

https://stackoverflow.com/questions/8441063/how-should-i-use-urlfetch-here

On production I used another variable. I thought it did not matter that it had whitespace. When I try variables that do not contain whitespace it works.
So could you please tell me how I should encode the url variable to admit whitespace and other “special” characters?

Thank you

  • 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-27T10:47:38+00:00Added an answer on May 27, 2026 at 10:47 am

    Just encode your querystring part

    Like:

    param = {"address" : region,
            "sensor" : "false"
            }
    

    or

    param = [("address", region), ("sensor", "false")]
    

    then

    encoded_param = urllib.urlencode(param)
    url = 'http://maps.googleapis.com/maps/api/geocode/json'
    url = url + '?' + encoded_param
    result = urlfetch.fetch(url)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple object that get's geocoding data from the Google Maps API
I am implementing a contact importer and will be geocoding the contacts that are
I am currently working on an application that allows reverse geocoding using silverlight +
I've seen that it's possible to get the latitude and longitude (geocoding, like in
I have a geocoding function that is pulling the address values entered into a
I created a custom LocationGenerator class that uses CoreLocation and Reverse Geocoding, and generates
I am writing an app that will use Reverse Geocoding to translate the user's
I'm using python and I need to map locations like Bloomington, IN to GPS
I'm starting with geocoding, and after read a few things I realize that are
HI..I doing geocoding in android map.(i.e)getting address as input from user & locate that

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.