Hello,

Sorry if you dont want to be in "to" ..

El 9/6/2015 10:44 a. m., "mudongliang" <[email protected]>
escribió:
>
> I wonder whether this is a bug for python urllib2.
> The following is the code I used:
>
>     target = protocol + "://" + location + directory + target_file
>     start = datetime.now()
>     try:
>         urlrequest = urllib2.Request(target)
>         urlresponse = urllib2.urlopen(urlrequest, timeout=4)
>
>         urldata = urlresponse.read()
>
>     except (urllib2.URLError, socket.timeout):
>         return "ERR"
>
>     stop = datetime.now()
>     time_difference = stop - start
>     print("\ntime diff is " + str(time_difference.total_seconds()))
>
> According to the definition of socket.timeout, time_difference will
> be no more than 4 seconds or no part of output.

I think timeout is refering to connection timeout. Ser at doc of urlopen:

"The optional *timeout* parameter specifies a timeout in seconds for
blocking operations like the connection attempt (if not specified, the
global default timeout setting will be used). This actually only works for
HTTP, HTTPS and FTP connections."

Regards

Reply via email to