Resolving 10060, 'Operation timed out'

W

willitfw

Does anyone know how to prevent this error from occurring: IOError:
[Errno socket error] (10060, 'Operation timed out').

I am using the following code without any luck. Obviously I am missing
something.

import socket
socket.setdefaulttimeout(20)

Thank you in advance.

Tom Williams
 
L

Larry Bates

My manual says that socket has a settimeout(value) but I don't
seem to find anything on socket.setdefaulttimeout method you
refer to.

<snip>
settimeout( value)

Set a timeout on blocking socket operations. The value argument can be a
nonnegative float expressing seconds, or None. If a float is given, subsequent
socket operations will raise an timeout exception if the timeout period value
has elapsed before the operation has completed. Setting a timeout of None
disables timeouts on socket operations. s.settimeout(0.0) is equivalent to
s.setblocking(0); s.settimeout(None) is equivalent to s.setblocking(1). New in
version 2.3.

-Larry Bates
 
P

Peter Hansen

Larry said:
My manual says that socket has a settimeout(value) but I don't
seem to find anything on socket.setdefaulttimeout method you
refer to.

Larry, the module has a setdefaulttimeout() function,
while socket objects themselves have a settimeout().

To the OP: did you already create your socket object
before you called setdefaulttimeout()? That setting
applies only to *new* sockets created after you call
the function...

-Peter
 
W

willitfw

I'm including the code that I've been using. I am relatively new to
python, and not sure if a socket was created:

*****************
import socket

socket.setdefaulttimeout(None)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

from urllib import urlopen
import urllib, urlparse, string, time

web = 'http://www.python.org'

socket.setdefaulttimeout(1200)
website = web

print website

pinhtml = urllib.urlopen(website)
data = pinhtml.read()
sock.close()
pinhtml.close()

*****************
 
P

Peter Hansen

willitfw said:
I'm including the code that I've been using. I am relatively new to
python, and not sure if a socket was created:

*****************
import socket

socket.setdefaulttimeout(None)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

The last line above creates a socket... and I suspect
the line ahead of it is redundant.

More importantly, you can probably avoid using
the defaulttimeout thing if you just do settimeout
on the newly created socket...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top