[Twisted-Python] POSTing http requests

Lenny G Arbage alengarbage at yahoo.com
Thu Mar 10 22:32:11 MST 2005


  I just realized that this is a bit more involved
than I at first expected.  It would be nice to be able
to send the upload request without holding all of
postdata in memory, and getPage(), even when I get
past the below problem (which can be done by calling
something like encode_multipart_formdata() as defined
at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/146306),
doesn't seem to allow for that.

  Fabian Seisen's urllib2_file at
http://fabien.seisen.org/python/urllib2_multipart.html,
 does work without requiring the upload to sit in
memory all at once, but it doesn't appear to be
asynchronous and it doesn't appear to work with Python
2.4 right now, either.

  Is there some way I can make this work with
HTTPClientFactory?  If not, what should I be looking
at?  In the case of large file uploads, wouldn't it be
advisable to send the headers/seperators first, then
do a chunk by chunk read of the file and send these
chunks one at a time (but in quick succession).  To do
that, it seems like a write() method is necessary --
is that in the IConsumer interface?

  Thanks for any guidance you can give me -- as you
can tell I'm new to twisted.

    Thanks
    Lenny G.


--- Lenny G Arbage <alengarbage at yahoo.com> wrote:
> How do I correctly set up the payload for a POST
> file
> upload?  I see that I can add a "method='POST'" and
> "postdata=something" to getPage(), but it's that
> 'something' that I'm stuck on.  I'm wondering if
> there
> isn't a convenience method for putting the right
> stuff
> in the HTTP header (Content-Type: multipart...") and
> in the body (-----seperator, etc).
> 
> I haven't been able to find an answer in the mailing
> list for the above (and google doesn't seem to know,
> either), but I'm sure there's a really simple way to
> do it.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the Twisted-Python mailing list