SSL and POST with httplib or urllib

Phil Mayes nospam at bitbucket.com
Tue Jun 6 01:28:51 EDT 2000


jsantaniello at my-deja.com wrote in message <8hhttv$7r6$1 at nnrp1.deja.com>...
>The cgi (which I have no control over) returns a nice html page that
>says it can't process my request because of a "format or context error".
>
>A simple test html page I made:
><html>
><body>
><form method=POST action=https://www.experian.com/cgi-bin/ccredit.cgi>
><input type=hidden name=0 value=1>
><input type=SUBMIT>
></form>
></body>
></html>
>
>works from a browser but:
>
>import httplib
>h = httplib.HTTPS('www.experian.com')
>h.putrequest('POST', '/cgi-bin/ccredit.cgi?0=1')
>h.putheader('Accept', 'text/html')
>h.putheader('Accept', 'text/plain')
>h.endheaders()
>errcode, errmsg, headers = h.getreply()
>print errcode # Should be 200
>f = h.getfile()
>print f.read()
>f.close()
>
>from a module returns a different page with the "context" error
>business. And it's not a cookie issue.
>
>Am I doing something wrong with specifiing POST?

You're sending it like a GET.  IIRC, the URL is /cgi-bin/ccredit.cgi
and the data is "0=1".  You'll also need a Content-Length header line
with a value of 3:
  h.putheader('Content-length', '%d' % len(data))
  h.endheaders()
  h.send(data + '\r\n')
(Maybe the \r\n is redundant.)
--
Phil Mayes    pmayes AT olivebr DOT com
Olive Branch Software - home of Arranger
http://www.olivebr.com/







More information about the Python-list mailing list