how to deal with socket.error: (10060, 'Operation timed out')
gregarican
greg.kujawa at gmail.com
Sat Mar 18 07:41:23 EST 2006
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
More information about the Python-list
mailing list