I'm looking to get more information about IOError: [Errno socket error] [Errno 10060] when using urlopen in Python 2.7. I am using my personal 35MB/s Internet connection (no proxy).
I've been opening multiple webpages from various websites using a Python script and randomly get this error message from time to time:
webpage = urlopen('http://www.thewebpage.com')
IOError: [Errno socket 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
This error appeared after trying to open pages from different websites. Therefore, it doesn't seem to be related exclusively to the opening of pages from one particular website. I also got this error using mechanize.
My questions are :
Is this error related to the fact that I am sending multiple requests to the same server within a short amount of time? Would a time-out reduces the chance of getting this error?
Is there any way to prevent it? Could I use a conditional statement to prevent the script from crashing?
My script takes around an hour to run and having to rerun it due to this error is fairly unpleasant.
Sending multiple requests to the same server in short succession could very well cause the server not to respond, since your requests might look like a ddos attack. You can catch the exception with a try-except clause, and try again.
Related
I'm trying to run a simple Python script which connects to a website and reads a document on the website, but it fails. Any help, would be most welcome, thank you!
The code is as follows:
import urllib.request
fhand = urllib.request.urlopen('http://www.py4inf.com/code/romeo.txt')
for line in fhand:
print (line.strip())
And I'm getting the following two error messages:
TimeoutError: [WinError 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
urllib.error.URLError: {urlopen error [WinError 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}
This is the windows error, not urllib's one. The latter has a handy default timeout value of never, but the former depends on settings of your proxy (with default being 60 seconds for initial connection and 120 for any further GET requests.
I can't help much with windows, but at least now you know where to look.
I had this same issue, and tried specifying a timeout in the urllib.request.urlopen, but no dice.
What did work was including a header, as described here. The first answer worked, and so did the second, so I used the simpler, second solution.
My Python code downloads a file from our website. The code fails to download the file on certain clients computers. I cant for the life of me figure out why the file fails to download when the script runs on certain computers but works on others.
The error that occurs on certain computers is:
<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>
The clients confirm they are connected to the internet and they can successfully download the same file(same url) through a web browser. Its incredibly weird that the script works on some computers and not on others, that they are connected to the internet but cannot download the file and that they can download the file through a browser but not through my script? Maybe the cause it that they are not an admin user?
What can cause this kind of error?
My simple code:
try:
source_buffer = urllib2.urlopen(URL)
source_code = source_buffer.read()
source_buffer.close()
return source_code
except Exception, e:
print e
PS: Do you think this is a proxy error? If it is can you explain what exactly is going wrong? Proxies have always confused me - well I understand when using a proxy all http, https, ftp requests go through a proxy computer (intermediary) before going out to the internet but I dont understand how this error can be caused from a proxy? Whats going wrong? Whats occurring?
It could be proxy, or looking at the error message, it could also be that local/personal firewall settings are blocking the outgoing requests from your application, or responses from the server from reaching your application. Local firewall settings could easily vary between computers, and this might account for the problem.
I am trying to develop a simple bittorrent client in Python for my own learning purpose. I am able to get the connection request/response working correctly. But as soon as I issue announce request I get the "socket.error: [Errno 10054] An existing connection was forcibly closed by the remote host" error. I have tried my code on multiple udp trackers but I get the same issue with all of them.
For you reference my code: https://gist.github.com/zhaphod/9870825
Code is fairly small at 137 lines and the issue occurs at line 112.
I would appreciate any hints/solutions to the issue.
I'm trying to write a script that logs into my email server(yahoo) and checks for messages from a certain sender. This is my first time useing the IMAP module and I can't seem to get it to work. Right now I have only a few lines of code.
from imaplib import *
server = IMAP4_SSL('mail.yahoo.com')
server.login('myusername','mypassword')
mail_folders = server.list()
for folders in mail_folders:
print(folders)
at this point all I'm trying to do is login to the mail server and retrieve a list of folders. However I never get connected. the interpreter throws a
[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'm not sure if this has something to do with SSL or what. I have managed to get a connection with httplib.HTTPSConnection, But I would rather use IMAP then webscrape.
I think the problem is just the server name that is wrong. Replacing 'mail.yahoo.com' with 'imap.mail.yahoo.com' worked for me.
I'm using python socket to connect to a server but sometimes I get this:
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
when I call the socket.connect method
s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((self._ipv4address, host_port))
try:
s.connect((dest_ip, dest_port))
except:
raise
Why am I seeing this error? And how do I solve the problem?
You don't need to bind the socket (unless the remote server has an expectation of incoming socket) - it is extremely rare that this would actually be a requirement to connect.
Instead of using sockets to open a website, use urllib2 or mechanize if you need to twiddle forms. They manage cookies, sessions, page state, etc.. Much easier.
Also, if you fail to to connect.. don't give up! Try again, some sites can be pokey to respond. Some may not respond for a while depending - handle it better. Instead of just raising the error, wrap your connection method with an exponential backoff decorator.