[Tutor] httplib & keep-alive
Michael Barrett
mike@daboyz.org
Mon Mar 17 17:07:02 2003
Hi, can someone please post how to successfully re-use a HTTP/1.1 connection viah httplib? The code below doesn't seem to work- the exception is below the code.
##############
#!/usr/local/bin/python
import httplib, sys
httpcon = httplib.HTTPConnection('<website>')
httpcon.debuglevel = 1
httpcon.putrequest('GET', 'http://<website>/ocd/')
httpcon.putheader('Connection','Keep-Alive')
httpcon.endheaders()
reply = httpcon.getresponse()
redirLoc = reply.getheader('Location')
if redirLoc:
print "Found Location header, redirecting to " + redirLoc
httpcon.putrequest('GET', redirLoc)
httpcon.putheader('Connection', 'close')
httpcon.endheaders()
newreply = httpcon.getresponse()
##############
######### Exception
connect: (<website>, 80)
send: 'GET http://<website>/ocd/ HTTP/1.1\r\nHost: <website>\r\nAccept-Encoding: identity\r\nConnection: Keep-Alive\r\n\r\n'
reply: 'HTTP/1.1 302 Found\r\n'
header: Date: Mon, 17 Mar 2003 22:03:00 GMT
header: Server: Apache/1.3.27 (Unix)
header: Location: http://<website>/ocd/index.py
header: Keep-Alive: timeout=15, max=100
header: Connection: Keep-Alive
header: Transfer-Encoding: chunked
header: Content-Type: text/html; charset=iso-8859-1
Found Location header, redirecting to http://<website>/ocd/index.py
send: 'GET http://<website>/ocd/index.py HTTP/1.1\r\nHost: <website>\r\nAccept-Encoding: identity\r\nConnection: close\r\n\r\n'
Traceback (most recent call last):
File "./redirect.py", line 21, in ?
newreply = httpcon.getresponse()
File "/usr/local/lib/python2.2/httplib.py", line 752, in getresponse
raise ResponseNotReady()
httplib.ResponseNotReady
--
________________________________________________________________________
Mike Barrett | "I used to read, now I go to raves."
mike@daboyz.org | -- Random MUNI Rider, speaking
www.daboyz.org | to my friend Allison.
------------------------+-----------------------------------------------