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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:28:54+00:00 2026-06-10T14:28:54+00:00

I have got URLs stored in a list which are supposed to be passed

  • 0

I have got URLs stored in a list which are supposed to be passed to urllib2. However, urllib doesn’t seem to like this very much and I just cannot see why!

here is what I have got:

url = list[1]
response = urllib2.urlopen(url)
html = response.read()

The URL is a google maps Directions Web API URL of the kind:

http://maps.googleapis.com/maps/api/directions/json?origin=[origin]&destination=[destination]&waypoints=optimize:true|[waypoint1]|[waypoint2]&sensor=false

Now, if I try to run this, the retrieved html always looks something like this:

{
"routes" : [],
"status" : "INVALID_REQUEST"
}

Indicating that something is wrong with the passed URL. If however, I take the URL and assign it directly, like so:

url = "http://maps.googleapis.com/maps/api/directions/json?origin=[origin]&destination=[destination]&waypoints=optimize:true|[waypoint1]|[waypoint2]&sensor=false"
response = urllib2.urlopen(url)
html = response.read()

The result will happily come through with the (for me) essential end part looking like this:

         "warnings" : [],
         "waypoint_order" : [ 2, 0, 7, 5, 6, 4, 3, 1 ]
      }
   ],
   "status" : "OK"
}

My (hopefully not too stupid) question is therefore: why does urllib do its job when the URL is assigned directly but not if it comes from a list??

Thank you very much for your help,
J

PS: Is there a reason why the forum-software always cuts off my ‘Hi all’ greeting?

  • 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-06-10T14:28:55+00:00Added an answer on June 10, 2026 at 2:28 pm

    I have finally resolved the issue!

    Was pretty easy once I stepped back for a moment and thought about it again:
    I did get an answer from google’s Web API which means that urllib2 did pass something. However, it must have been sending something that didn’t make any sense to the API backend. The URL containing German addresses I lucky-guessed the problem being caused by umlauts.

    So I simply passed my URL through a function replacing each umlaut with its non-umlaut alternative and suddenly everything seemed to work fine.

    If anybody comes accross a similar issue, here’s how I solved it:

    # Function for replacing all umlauts
    def replaceUmlauts(text):
        dic = {'Ä':'Ae', 'ä':'ae', 'Ö':'Oe', 'ö':'oe', 'Ü':'Ue', 'ü':'ue', 'ß':'ss'}
        for i, j in dic.iteritems():
            text = text.replace(i, j)
        return text
    

    Then simply use

    response = urllib2.urlopen(replaceUmlauts(url))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got four routes defined like this: //Project list with page number routes.MapRoute(
I have got page which I would like to cache using the OutputCache directive.
Given the fact that I have a list of urls (stored in the variable
This may be stupid question. I have app with a bunch of URLs stored
I have got some URLs like that /WebSite/Movies/807?sort=MovieName&sortdir=DESC&p2=2&p3=3 /WebSite/Movies/807?sort=MovieName&sortdir=ASC&p4=4&p5=5 and I need to get
I have got a list of many web page URLs.. and all of them
I have got this code: function init(){ if (typeof window.jQuery !== 'function') { var
I have got a form into which information is entered, and a drop down
I have got a table [newsletter] in the db, which saves the email address,
I have got two pages. example.com/php.com and example.com. I use this function to set

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.