Use of httplib?

David Lees DavidL at nospammy_raqia.com
Wed Dec 13 16:04:22 EST 2000


I am running the client code below to try and send and receive text from
a server.  My problem is that I do not know how to recieve back an
arbitrary number of lines.  In a test case, when I know the exact number
of lines as shown below (e.g. 11) I can use readline.  However, in
general I do not know how many lines there are and the program hangs on
the connection when  I accidentaly read to the end.  The comment out
pieces of code also either hang or do not give back all the text.

I am copying from the Library Reference section 11.4, but it does not
seem to document the readline, read or readlines methods for http.

Thanks in advance for any help/pointers.

david lees


h = httplib.HTTP("192.168.0.3:50006")
h.putrequest('POST','/rpchandler HTTP/1.0')
h.putheader('Content-Type', 'text/xml')
h.putheader("Content-length", "%d" % len(bod))
h.endheaders()
h.send(bod)
reply, msg, hdrs = h.getreply()
print reply
print msg
print hdrs
f = h.getfile()

#data=f.read()
#print data

#data=f.readlines()
#print data

for i in range(11):
    data=f.readline()
    print data

    
#while 1:
#   data=f.readline()
#    if not data:
#       break
#    print data

f.close()
h.close()



More information about the Python-list mailing list