Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Scripting HTTP POST - multipart/form-data

Reply
Thread Tools

Scripting HTTP POST - multipart/form-data

 
 
Jeff Shannon
Guest
Posts: n/a
 
      07-19-2004

I'm looking to script a routine file-upload through an HTTP server
(which I don't have access to). I've got specs on the CGI app that
receives this upload (i.e. field names and expected contents).

However, it looks like urllib/urllib2 won't handle multipart/form-data
POSTs. I tried hacking together something with httplib, but I'm
severely hampered by the fact that I don't know HTTP well enough to know
what headers I need to send, and my attempts to find (through Google) a
list of necessary headers haven't turned out too well. I really don't
want to have to scour the entire HTTP specs for this...

At a quick glance, it seems that PyCURL may do what I need, but it's...
well, not exactly user-friendly (at least for someone with zero
experience with libcurl), and the machine I'm trying to send from (RH9)
doesn't have libcurl installed. (I'd prefer to not have to install
anything just for this, if I can avoid it...)

Is there another (preferably all-python) library that will work for
this? Or perhaps a friendly how-to that'll explain what I need to know
to use httplib?

Jeff Shannon
Technician/Programmer
Credit International

 
Reply With Quote
 
 
 
 
John J. Lee
Guest
Posts: n/a
 
      07-19-2004
Jeff Shannon <> writes:

> I'm looking to script a routine file-upload through an HTTP server
> (which I don't have access to). I've got specs on the CGI app that
> receives this upload (i.e. field names and expected contents).
>
> However, it looks like urllib/urllib2 won't handle multipart/form-data
> POSTs.


Neither should have any problem with multipart/form-data. They don't
actually provide and specific support for it either, though.

[...]
> Is there another (preferably all-python) library that will work for
> this?

[...]

Yes, one that works on top of urllib2:

http://wwwsearch.sf.net/ClientForm


Search for .add_file on that page for an example of file upload. IIRC
I've posted examples of that here in the past, too.


John
 
Reply With Quote
 
 
 
 
John J. Lee
Guest
Posts: n/a
 
      07-19-2004
Jeff Shannon <> writes:

> I'm looking to script a routine file-upload through an HTTP server
> (which I don't have access to). I've got specs on the CGI app that
> receives this upload (i.e. field names and expected contents).

[...]

Forgot to add: if I had to do this and wanted to use ClientForm (which
I certainly would , I'd just write a snippet of HTML:

formHtml = """\
<form action="http://www.example.com/cgi-bin/spam.cgi">
<input type="text" name="nrEmails" />

<input type="checkbox" name="spamType" value="ludicrous" />
<input type="checkbox" name="spamType" value="absurd" />
</form>
"""

import StringIO
from ClientForm import ParseFile

forms = ParseFile(StringIO.StringIO(formHtml), "http://www.example.com/")
....


Which is surely a very readable way of writing down such a spec

I should point this out in the docs...


John
 
Reply With Quote
 
Jeff Shannon
Guest
Posts: n/a
 
      07-20-2004
John J. Lee wrote:

>Jeff Shannon <> writes:
>
>
>
>>I'm looking to script a routine file-upload through an HTTP server
>>(which I don't have access to). I've got specs on the CGI app that
>>receives this upload (i.e. field names and expected contents).
>>
>>However, it looks like urllib/urllib2 won't handle multipart/form-data
>>POSTs.
>>
>>

>
>Neither should have any problem with multipart/form-data. They don't
>actually provide and specific support for it either, though.
>
>


True. I realized that, I was merely inexact with my wording. The
problem being that I don't know how to enhance them to add that support...

>[...]
>
>
>>Is there another (preferably all-python) library that will work for
>>this?
>>
>>

>[...]
>
>Yes, one that works on top of urllib2:
>
>http://wwwsearch.sf.net/ClientForm
>
>


Ah, thank you! That looks like just what I needed.

Jeff Shannon
Technician/Programmer
Credit International

 
Reply With Quote
 
Wade Leftwich
Guest
Posts: n/a
 
      07-21-2004
Jeff Shannon <> wrote in message news:<>...
> I'm looking to script a routine file-upload through an HTTP server
> (which I don't have access to). I've got specs on the CGI app that
> receives this upload (i.e. field names and expected contents).
>


Here's a recipe I posted to the Python Cookbook a couple of years ago.
Works with IIS.
http://aspn.activestate.com/ASPN/Coo.../Recipe/146306

-- Wade Leftwich
Ithaca, NY
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
Why getInputStream in a http servlet request isn't getting the datasent by browser HTTP POST action? James Java 3 11-25-2005 11:17 PM
How to enter to .aspx page by http connection using http POST request farazkazmi@gmail.com Java 6 08-29-2005 02:58 PM
Using a Scripting Language as Your Scripting Language DaveInSidney Python 0 05-09-2005 03:13 AM
Python is the best and most popular general purpose scripting language; the universal scripting language Ron Stephens Python 23 04-12-2004 05:32 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57