Mailing List Archive

Problems with CGI, genCGI and a multipart form
I'm having trouble getting cgi.FieldStorage to read data posted as
multipart/form-data.

Right now I am testing a script using stdin piped from a test file. The
test file has everything after the header from a posted form, e.g.,:

-----------------------------172981055621895
Content-Disposition: form-data; name="section"

production
-----------------------------172981055621895
Content-Disposition: form-data; name="title"

This is the title

etc...

Environment variables for Content-type, Content-Length, and
REQUEST_METHOD (POST) are set correctly.

When the script is run, cgi.FieldStorage is called with stdin to
populate self.formdict, but the results are always empty...

A similar script that is not a multipart POST (just a standard POST)
works fine, where stdin is:
MessageType=Suggestion&Subject=Web+Site&SubjectOther=&Comments=&UserName
=&UserEmail=&UserTel=&UserFAX=

Am I missing an environment variable? Is there a trick I'm missing?

I've tried including the header; not including the header; and other
variations on the test input.

Help!

Thanks in advance,

pcc


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Problems with CGI, genCGI and a multipart form [ In reply to ]
On Jun 17, 1999, peter_carl@my-deja.com wrote:

>I'm having trouble getting cgi.FieldStorage to read data posted as
>multipart/form-data.

>Right now I am testing a script using stdin piped from a test file. The
>test file has everything after the header from a posted form, e.g.,:
>
> -----------------------------172981055621895
> Content-Disposition: form-data; name="section"
>
> production
> -----------------------------172981055621895
> Content-Disposition: form-data; name="title"
>
> This is the title
>
>etc...
>
>Environment variables for Content-type, Content-Length, and
>REQUEST_METHOD (POST) are set correctly.

1. Did you end the multipart data with an additional "--" to your last boundary:

-----------------------------172981055621895--

This is required to end the data portion correctly.

2. BTW, is there any reason you test your cgi script with a file via stdin
(plus somehow set your environment vars)? Isn't it simpler to just set up
a httpd on your development host to test your scripts? Preparing the http headers
and data file manually for testing is, in our opinion, error-prone.

3. We have used multipart POST cgi (with cgi.py) without problem in our
application. We always test directly with a httpd.

yours-common-gateway-ly

alan kang
http://www.epls.com - free groupware online