HTTP POST File without cURL

Jarkko Torppa torppa at staff.megabaud.fi
Wed Sep 9 15:47:22 EDT 2009


On 2009-09-09, John D Giotta <jdgiotta at gmail.com> wrote:
> I'm working with an API that allows me to POST a zip file via HTTP and
> the documentation uses a cURL example. cURL works, but when I try to
> POST the file via python it fails.
> I don't want to use cURL (since I'm trying to be transparent and
> dependency-less), but I can't find anything online that works.
>
> When I use multipart/form-data methods (found here
> http://code.activestate.com/recipes/146306/), the recipient cannot
> decipher the attached file.
>
> This is about the most difficult thing I've had to do with python and
> yet it is supposed to be the very basics of HTTP.
>
> Example cURL command:
> curl -v -u username:passwd --data-binary @/home/jdgiotta/test.zip -H
> "Content-Type: application/zip" https://host/selector
>
> Is there a valid way to do this?

Maybe, but reading from curl manpage it seems that that is doing

POST /selector ...
Content-type: application/zip

data


The backend is broken, they should have used PUT for that. Search
for "python http put" and adapt, or lookt at urllib(2)/httplib and
roll your own.

-- 
Jarkko Torppa



More information about the Python-list mailing list