problem with http post

Alan Kennedy alanmk at hotmail.com
Thu Apr 4 16:47:42 EST 2002


Warning: I haven't tested any of this.

mongiaamit at yahoo.com (Amit Mongia) wrote:
> See i have a small problem.

...

> But the following code gives me an "Invalid number of arguements"
> error.
> 
> encdata = 'myaddress=addressvalue1'
> conn = httplib.HTTP("karlulbrich.com")
> conn.putrequest("POST", "/address/accept/")
> conn.putheader('Content-type', 'application/x-www-form-urlencoded')
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
This declaration is telling the server that the parameters are
"url-encoded", so it will expect to see something like this :-

http://karlulbrich.com//address/accept/?myaddress=addressvalue1

But you're sending the form data as a part of the http message body,
so the server might be being confused by this.

If you want to send the data as a part of the message body, you should
set the content type to "multipart/form-data"

So you could try this

conn.putrequest('POST', '/address/accept/')
conn.putheader('Content-type', 'multipart/form-data')
conn.putheader('Accept', 'text/plain') 
conn.endheaders()
conn.send(encdata)

You might want to have a read of the section in the HTML 4 spec about
Form Submission. I guarantee it will clear matters up for you (a
little, at least).

http://www.w3.org/TR/REC-html40/interact/forms.html#submit-format

HTH,

Al.



More information about the Python-list mailing list