Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

using httplib

5 views
Skip to first unread message

Jeff Shipman

unread,
Apr 16, 2002, 4:57:11 PM4/16/02
to
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: shi...@nmt.edu
Computer Science Major ICQ: 1786493
New Mexico Institute of Mining and Technology
Homepage: http://www.nmt.edu/~shippy

Jeff Shipman

unread,
Apr 16, 2002, 5:23:39 PM4/16/02
to
Nevermind. I was forgetting to calculate and
send the 'Content-length' header for my send()
string. Once I did that, I got back the INVALID
response.
0 new messages