Why can't I get Python's urlopen() method to work on Windows?

Your code is not the problem here.

Do you have any Proxy settings in your IE?

This says the python documentation for urllib.urlopen:

In a Windows environment, if no proxy environment variables are set,
proxy settings are obtained from the registry's Internet Settings
section.


Try using urllib2 if it is feasible to change some lines of code. Set the timeout argument in seconds

For example:

urllib2.urlopen(http://www.abc.com/api, timeout=20)

Here the connection persists for a longer duration. So if for example you are reading an XML file that is too large it avoids incomplete reading.

The above code will never work if the Net connection is slow or it breaks suddenly.

Tags:

Python

Urllib