I'm trying to do PUT to REST using urllib2 following the example I found on stackoverflow:
Is there any way to do HTTP PUT in python
I don't understand why I get error an error.
Here's an excerpt of my code:
import urllib2
import json
content_header = {'Content-type':'application/json',
'Accept':'application/vnd.error+json,application/json',
'Accept-Version':'1.0'}
baseURL = "http://some/put/url/"
f = open("somefile","r")
data = json.loads(f.read())
request = urllib2.Request(url=baseURL, data=json.dumps(jsonObj), headers=content_header)
request.get_method = lambda: 'PUT' #if I remove this line then the POST works fine.
response = urllib2.urlopen(request)
print response.read()
if I remove the PUT option I'm trying to set then it posts it find but it will error out when I try and set get_method to PUT.
To be sure that the REST services aren't causing the issues I tried using cURL to do a PUT and it worked fine.