473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to deal with socket.error: (10060, 'Operation timed out')

I wrote a script to get 100 pages from a server.
like below:

1:import httplib
2:conns = httplib.HTTPConnection("www.mytest.com")
3:conn.request("GET", "/")

sometimes a socket error was raised.

File "D:\usr\bin\lib\httplib.py", line 627, in connect
raise socket.error, msg
socket.error: (10060, 'Operation timed out')

how to catch this kind of error then retry the "GET" operation?

btw:
If I want to get many page on same server, which lib is the best
choice? I only know httplib,urllib and urllib2.
thanks a lot.

Mar 18 '06 #1
3 16532
JuHui wrote:

I wrote a script to get 100 pages from a server.
like below:
1:import httplib
2:conns = httplib.HTTPConnection("www.mytest.com")
3:conn.request("GET", "/")
sometimes a socket error was raised.
File "D:\usr\bin\lib\httplib.py", line 627, in connect
raise socket.error, msg
socket.error: (10060, 'Operation timed out')
how to catch this kind of error then retry the "GET" operation?


You can use this below if you only want one retry ---

import httplib
conns = httplib.HTTPConnection("www.mytest.com")

try:
conn.request("GET", "/")
except:
try:
conns.request("GET", "/")
except:
print "I bombed out!"

# blah blah blah

Mar 18 '06 #2
"JuHui" wrote:
I wrote a script to get 100 pages from a server.
like below:

1:import httplib
2:conns = httplib.HTTPConnection("www.mytest.com")
3:conn.request("GET", "/") sometimes a socket error was raised.

File "D:\usr\bin\lib\httplib.py", line 627, in connect
raise socket.error, msg
socket.error: (10060, 'Operation timed out')
(given the code you quoted, a NameError would be more likely...)
how to catch this kind of error then retry the "GET" operation?


the same way as you'd catch any other kind of error in Python:

try:
<operation>
except <exception>:
<error handler>

if you want to repeat an operation until it succeeds, use a loop:

while 1:
try:
<operation>
except <exception>:
<error handler>
else:
break # success

for details, see

http://docs.python.org/tut/node10.html

</F>

Mar 18 '06 #3
thanks!
I try the "try" before, but can't catch the socket error. so strange,
maybe my code was error.
I wrote a retry code block as below.

import httplib,time

while 1:
try:
conn = httplib.HTTPConnection("www.test.com")
conn.request("GET", "/")
print "success"
break
except:
print "error"
time.sleep(2)

Mar 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: willitfw | last post by:
Does anyone know how to prevent this error from occurring: IOError: (10060, 'Operation timed out'). I am using the following code without any luck. Obviously I am missing something. import...
0
by: Ajay Abhyankar | last post by:
Hi, I am trying to upload zip files using ftplib module. The server has Vsftpd 2.0.3 installed on it. I was able to succesfully upload files using ftplib and Vsftpd on the server locally...
0
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
4
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
11
by: Sumit Acharya | last post by:
I am using following script to connect to the server and i try the connection for 1000 times. Some times it succeeds for all the 1000 times,but some times it fails with error:- 10060, 'Operation...
0
by: Vidds | last post by:
Hi All, I am getting operation timed out for one of my methods and its directly taking to my custom error page. my question is that is there any way where in i can trap this operation time and...
0
by: Stimp | last post by:
I have transferred several ASP.NET projects from one pc to another. I set up IIS for all of them. Created Virtual Directory applications successfully. They all work fine.. all except one. I...
0
by: Just D. | last post by:
How could I fix this annoying bug? I have a large solution with 29 projects, including 28 class libraries and 1 Web Application written in C#. It was working with IE6 good enough and when I was...
1
by: Pratappeddinti | last post by:
I am getting operation timed out exception when i am using webservices. What is this operation timed out exception. How can i fix this problem.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.