Re: pycurl and rest PUT interface

From: Matchek <>
Date: Sun, 7 Apr 2013 19:36:52 +0100

2013/1/22 Mark Seger <>:
> curl -X PUT -k -i -H X-Auth-Token:$auth -T xyzzy ${url}/xyzzy/xyzzy
> The variable $auth contains an authentication token and xyzzy is a file I
> want to up load to the destination pointed to by $url and the subdirectory
> xyzzy/xyzzy. Ultimately I really want to do this from an in-memory data
> structured loaded into a variable but was thinking trying to upload a file
> first might be a good starting point.
> I do see a POST option tut that won't help.

Daniel Steinberg's hint (--libcurl) lead me to the solution: if you
use pycurl, you need to not use setopt(pycurl.PUT, 1), but
setopt(pycurl.CUSTOMREQUEST, "PUT") instead.

Full writeup:

I guess you need to trick pycurl into thinking it's making a POST
request, and only hack-in your own request type, which is what the "-X
PUT" option is doing on the command line.

Overall, --libcurl is a very useful tool. Even though it shows you a C
program, the code it shows pretty much directly translates into

Received on 2013-04-07