Doing POST opperations from Python

Aahz Maruch aahz at netcom.com
Tue Aug 31 20:23:06 EDT 1999


In article <14284.7351.644976.369476 at dolphin.mojam.com>,
Skip Montanaro  <skip at mojam.com> wrote:
>
>    Phil> I am trying to produce POST requests within python (to drive a web
>    Phil> based email client). I can do GET requests, but can understand how
>    Phil> to do post. I have read RFC1945 (Informational), but I can find
>    Phil> the info there either.  I understand that the data is sent as part
>    Phil> of the headers, but how?
>
>Depends which module you're using.  If you use a recent version of urllib,
>you can place your parameters in a dictionary, call urllib.urlencode to
>encode it and pass the results to urllib.urlopen:
>
>    import urllib
>    paramstring = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
>    f = urllib.urlopen("http://www.musi-cal.com/cgi-bin/query",
>		       paramstring)
>    print f.read()

I'm not positive, but I believe this appends paramstring to the URL
(through GET) instead of using POST.
--
                      --- Aahz (@netcom.com)

Androgynous poly kinky vanilla queer het    <*>      http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6  (if you want to know, do some research)




More information about the Python-list mailing list