Re: POST from a CGI

From: David M. Cooke (cookedm+news_at_physics.mcmaster.ca)
Date: 09/22/04


Date: Wed, 22 Sep 2004 16:17:30 -0400

fuzzyman@gmail.com (Michael Foord) writes:

> I'm receiving POST data to a CGI, which I'd like to forward to another
> CGI using urllib2.
>
> I have two options -
>
> 1) Parse the data using cgi.FieldStorage() and then rebuild the POST
> request into a dictionary - including any files (? uploading files by
> urllib2 untested and undocumented - examples seem to be for httplib).
>
> 2) Read the whole POST data in using sys.stdin.read(), rebuild the
> 'Content-type' and 'Content-length' headers and make the POST.
>
> Obviously (2) is a *lot* less fiddly and less error prone. *But* I'm
> getting 400 errors when I try it (server thinks request is malformed).
> I've checked the headers and the body data and they seem normal and I
> can't work it out.
>
> I wonder if anyone can see what I'm doing wrong......
> (Simple code shown first - then a straightforward example that ought
> to work and fails).
[snip]
> info = u.info() # info about the url
> pagetype = info.gettype()
> print 'Content-type: ' + pagetype + '\n'
> print u.read() # print the received page

I think this is your problem: print is adding an extra \n to the end,
so the length of the data doesn't agree with the Content-length
header. Use sys.stdout.write.

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca


Relevant Pages

  • Re: Please Stop It Rebuilding Everything!
    ... headers correctly, as one of the posters mentioned. ... suite of libraries that are being used in the project being built. ... Change your project settings so that "Use precompiled headers " is ... They do always rebuild ...
    (microsoft.public.dotnet.languages.vc)
  • RE: Please Stop It Rebuilding Everything!
    ... Thanks for your replies, and from what I see we don't seem to be doing ... We use precompiled headers for all headers that do not change often, ... Also lets say I regenerate 50 of our classes, mostly it will rebuild these ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Please Stop It Rebuilding Everything!
    ... > We use precompiled headers for all headers that do not change often, ... > rebuild it by setting to /Yc rebuilding one file to create the precompiled ... > Also lets say I regenerate 50 of our classes, ... >> Well back to twidling my thumbs. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: [SLE] Which version of Suse for these task ?
    ... you would have to rebuild the rpm repository too (the ... Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com ...
    (SuSE)
  • Unstructured Text Parsing
    ... I'm trying to parse a set of files where about the only thing I can ... I will then isolate page headers and ... The user will specify that the page header ... consists of 5 rows, for example. ...
    (microsoft.public.dotnet.languages.csharp)