472,780 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 16480
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.