I want to make an HTTP PUT request using Python 2.5.3

180 Views Asked by At

I have to use Python 2.5.3. This would be easy if I was using Python 3 request library, but sadly I am locked into Python 2.5.3 for work.

I need to make a 'PUT' request to a RESTful api to get a 204 response back.

I tried using urllib2 but I don't get the right response that I need

import urllib2

url='http://some_ulr.com'

try:
    request = urllib2.Request(url)
    request.get_method = lambda: 'PUT'

    response = urllib2.urlopen(request)
except urllib2.HTTPError , e:
    print e.code
    print e.read()

I keep getting a 505 as the response.

0

There are 0 best solutions below