Is there any way to do HTTP PUT in python


I need to upload some data to a server using HTTP PUT in python. From my brief reading of the urllib2 docs, it only does HTTP POST. Is there any way to do an HTTP PUT in python?

1/29/2010 4:15:24 PM

Accepted Answer

I've used a variety of python HTTP libs in the past, and I've settled on 'Requests' as my favourite. Existing libs had pretty useable interfaces, but code can end up being a few lines too long for simple operations. A basic PUT in requests looks like:

payload = {'username': 'bob', 'email': ''}
>>> r = requests.put("", data=payload)

You can then check the response status code with:


or the response with:


Requests has a lot synactic sugar and shortcuts that'll make your life easier.

11/24/2011 3:54:13 PM

import urllib2
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request('', data='your_put_data')
request.add_header('Content-Type', 'your/contenttype')
request.get_method = lambda: 'PUT'
url =

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow