How to resolve URLError: <urlopen error [Errno 10060]
Asked Answered
H

5

23

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:\Python27\lib\urllib2.py", line 126, in urlopen
>     return _opener.open(url, data, timeout)   File "C:\Python27\lib\urllib2.py", line 400, in open
>     response = self._open(req, data)   File "C:\Python27\lib\urllib2.py", line 418, in _open
>     '_open', req)   File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
>     result = func(*args)   File "C:\Python27\lib\urllib2.py", line 1207, in http_open
>     return self.do_open(httplib.HTTPConnection, req)   File "C:\Python27\lib\urllib2.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).

Halifax answered 4/4, 2013 at 20:8 Comment(4)
Works fine here. Is your internet working?Concentrated
It works on my Win7+Python2.7. The most possible issue is the proxy. See more here:https://mcmap.net/q/345577/-using-an-http-proxy-python-duplicate #2924203Reggiereggis
@Reggiereggis Post that as the answer, as that's most likely that's what the issue is.Halifax
@Halifax Posted. Hope it helps!Reggiereggis
R
17

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!

Reggiereggis answered 1/5, 2013 at 2:49 Comment(0)
M
6

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)
Merlynmermaid answered 29/5, 2020 at 7:14 Comment(0)
C
1

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

Coinstantaneous answered 28/12, 2017 at 13:56 Comment(1)
There is nothing I hate more than instructions without the correct names for tabs/optionsKanishakanji
C
1

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:\Users\gopal\AppData\nltk_data...
[nltk_data]   Unzipping corpora\stopwords.zip.

To verify:

print(stop[:10])
['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', "you're"]
Comanchean answered 26/2, 2023 at 16:10 Comment(0)
P
0

The best option is to connect your laptop/PC to mobile internet (hotspot) instead of your regular Wi-Fi. It worked for me.

Poetess answered 9/12, 2023 at 18:7 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Bunin

© 2022 - 2024 — McMap. All rights reserved.