curl-and-python

Re: Setting content type for HTTPPOST?

From: <johansen_at_opensolaris.org>
Date: Mon, 11 Oct 2010 11:16:45 -0700

On Mon, Oct 11, 2010 at 07:02:36PM +0200, Michael Wood wrote:
> Hi
>
> I'm using PycURL to upload a file but I'm having trouble figuring out
> how to specify the content type of the file. It's currently coming
> through as text/plain and the server seems to be converting the DOS
> line end characters to UNIX line end characters. When the file is
> uploaded, the server calculates the checksum to send back to the
> client so that the client knows that the file is not corrupted, so
> this EOL conversion breaks the checksum.
>
> At the moment I'm doing this:
>
> pf = [("report", (pycurl.FORM_FILE, filename)),
> ("checksum", self.checksum)]
> curl.setopt(pycurl.HTTPPOST, pf)
>
> I see there's a FORM_CONTENTTYPE option, but I haven't noticed
> documentation on it or exactly how to use it. Perhaps I've been
> looking in the wrong place, in which case I'd appreciate a pointer to
> the right place :)

At this point, the documentation is the code itself. When in doubt, I
look there first. The HTTPPOST code handles the arguments as FORMTYPE,
argument pairs. This looks a lot like the interface used here:

http://curl.haxx.se/libcurl/c/curl_formadd.html

I believe that the following should work for you:

        pf = [(pycurl.FORM_FILE, filename, pycurl.FORM_CONTENTTYPE,
        content_type)]
        curl.setopt(pycurl.HTTPPOST, pf)

HTH,

-j
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2010-10-11