using httplib

Jeff Shipman shippy at nmt.edu
Tue Apr 16 16:57:11 EDT 2002


I'm trying to use httplib under Python 1.5.2 to
submit a POST request to a remote server. I would
use Python 2.x if I could, but I do not control
the webserver I'm using and they do not plan to
upgrade for a long while. However, it's not working
for me. I have tried it with Python 2.x and it
works fine. Here's an example:

Python 2.x
headers = { "Content-type": "application/x-www-form-urlencoded" }
conn = httplib.HTTPConnection("www.paypal.com")
conn.request('POST', "/cgi-bin/webscr", "cmd=_notify-validate", headers)
res = conn.getresponse()
print res.read()
INVALID

INVALID is the correct response.

Python 1.5.2

conn = httplib.HTTP("www.paypal.com")
conn.putrequest('POST', "/cgi-bin/webscr")
conn.putheader('Content-type', 'application/x-www-form-urlencoded')
conn.endheaders()
conn.send('cmd=_notify-validate')
conn.getreply()
(200, 'OK', <mimetools.Message instance at 808e128>)
conn.getfile().read()
... Bunch of HTML because form wasn't posted properly ...

I've also tried it this way:

conn = httplib.HTTP("www.paypal.com")
conn.putrequest('POST', "/cgi-bin/webscr?cmd=_notify-validate")
conn.endheaders()
conn.getreply()
(200, 'OK', <mimetools.Message instance at 808c330>)
conn.getfile().read()
... Bunch of HTML because form wasn't posted properly ...

Any idea of how I can get this to work with Python 1.5.2?
Could I possibly just snag the 2.x httplib and it would
work under 1.5.2?

Thanks in advance,

-- 
Jeff "Shippy" Shipman     E-Mail: shippy at nmt.edu
Computer Science Major    ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy




More information about the Python-list mailing list