Python: URLError: <urlopen error [Errno 10060]

Question:

OS: Windows 7; Python 2.7.3 using the Python GUI Shell

I’m trying to read a website through Python, and several authors use the urllib and urllib2 libraries. To store the site in a variable, I’ve seen a similar approach proposed:

import urllib
import urllib2
g = "http://www.google.com/"
read = urllib2.urlopen(g)

The last line generates an error after a 120+ seconds:

> Traceback (most recent call last):   File "<pyshell#27>", line 1, in
> <module>
>     r = urllib2.urlopen(o)   File "C:Python27liburllib2.py", line 126, in urlopen
>     return _opener.open(url, data, timeout)   File "C:Python27liburllib2.py", line 400, in open
>     response = self._open(req, data)   File "C:Python27liburllib2.py", line 418, in _open
>     '_open', req)   File "C:Python27liburllib2.py", line 378, in _call_chain
>     result = func(*args)   File "C:Python27liburllib2.py", line 1207, in http_open
>     return self.do_open(httplib.HTTPConnection, req)   File "C:Python27liburllib2.py", line 1177, in do_open
>     raise URLError(err) URLError: <urlopen error [Errno 10060] A connection attempt failed because the connected party did not properly
> respond after a period of time, or established connection failed
> because connected host has failed to respond>

I tried bypassing the g variable and trying to urlopen("http://www.google.com/") with no success either (it generates the same error after the same length of time).

Asked By: Question3CPO

||

Answers:

The error code 10060 means it cannot connect to the remote peer. It might be because of the network problem or mostly your setting issues, such as proxy setting.

You could try to connect the same host with other tools(such as ncat) and/or with another PC within your same local network to find out where the problem is occuring.

For proxy issue, there are some material here:

Using an HTTP PROXY – Python

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

Hope it helps!

Answered By: Sheng

This is because of the proxy settings.
I also had the same problem, under which I could not use any of the modules which were fetching data from the internet.
There are simple steps to follow:
1. open the control panel
2. open internet options
3. under connection tab open LAN settings
4. go to advance settings and unmark everything, delete every proxy in there. Or u can just unmark the checkbox in proxy server this will also do the same
5. save all the settings by clicking ok.
you are done.
try to run the programme again, it must work
it worked for me at least

Answered By: RANA RAUFF

Answer (Basic is advance!):

Error: 10060
Adding a timeout parameter to request solved the issue for me.

Example 1

import urllib
import urllib2
g = "http://www.google.com/"
read = urllib2.urlopen(g, timeout=20)

Example 2

A similar error also occurred while I was making a GET request. Again, passing a timeout parameter solved the 10060 Error.

response = requests.get(param_url, timeout=20)
Answered By: DataFramed

just change your internet connection it is going to work..

Answered By: Amit semwal

I had to include NLTK’s stopwords for my data science project.
Anaconda says, "Couldn’t connect to network winError 10060",
A lot of answers talk a lot about proxy, just switch your data connection device, I switched from wi-fi to hotspot and it works fine.

Once, you get it done,

[nltk_data] Downloading package stopwords to
[nltk_data]     C:UsersgopalAppDatanltk_data...
[nltk_data]   Unzipping corporastopwords.zip.

To verify:

print(stop[:10])
['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're"]
Answered By: Gopal Sankar
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.