httplib hung on read
Aahz Maruch
aahz at netcom.com
Mon Jul 31 16:15:48 EDT 2000
In article <8m4m48+g8f4 at eGroups.com>, <ftian at cs.wisc.edu> wrote:
>
>I am using the httplib to get some webpage, it hungs sometimes
>in the following senario,
>
>http = httplib.HTTP('myhost')
>http.putrequest('GET', myurl)
>http.putheader(...)
>http.endheaders()
>
>errcode, errmsg, header = http.getreply()
>myfile = http.getfile()
># "Still OK here"
>page = myfile.read()
># Sometimes Cannot Reach here
<sigh> Yeah, that's because you've got some kind of unrecoverable
network error, and the default httplib doesn't handle. Fortunately,
because you're using httplib directly (instead of urllib), you can
modify HTTP.sock to have a timeout (assuming you're on a platform that
supports it).
The code looks more-or-less like:
HTTP.sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, timeout_ms)
--
--- Aahz (Copyright 2000 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
NOTE: end of September, Earthlink kills Netcom. My new permanent address is
aahz at pobox.com. I have not decided where to set my primary shell account.
Please do not send me e-mail condolences; my mailbox is already too big.
More information about the Python-list
mailing list