0

Frustratingly I'm needing to develop something on Python 2.6.4, and need to send a delete request to a server that seems to only support http 1.1. Here is my code:

httpConnection = httplib.HTTPConnection("localhost:9080")
httpConnection.request('DELETE', remainderURL)
httpResponse = httpConnection.getresponse()

The response code I then get is: 505 (HTTP version not supported)

I've tested sending a delete request via Firefox's RESTClient to the same URL and that works.

I can't use urllib2 because it doesn't support the DELETE request. Is the HTTPConnection object http 1.0 only? Or am I doing something wrong?

Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
jurasic
  • 1
  • 1
  • HTTPConnection uses `HTTP/1.1` by default. [505](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.6) is a problem with the *server*, so *it* doesn't seem to support version HTTP/1.1. – Martijn Pieters Sep 10 '12 at 14:53

3 Answers3

1

The HTTPConnection class uses HTTP/1.1 throughout, and the 505 seems to indicate it's the server that cannot handle HTTP/1.1 requests.

However, if you need to make DELETE requests, why not use the Requests package instead? A DELETE is as simple as:

import requests

requests.delete(url)

That won't magically solve your HTTP version mismatch, but you can enable verbose logging to figure out what is going on:

import sys
requests.delete(url, config=dict(verbose=sys.stderr))
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Thanks, would like to use that, but would mean going through a lengthy open-source approval process with my company. It's not a big tool I'm working on, just needs to make a couple of simple http interactions – jurasic Sep 10 '12 at 15:13
  • 1
    @jurasic: You mean any puny little external library needs approval? I pity your company. – Martijn Pieters Sep 10 '12 at 15:14
1

You can use urllib2:

req = urllib2.Request(query_url)
req.get_method = lambda: 'DELETE'   # creates the delete method
url = urllib2.urlopen(req)
Oleksandr Shmyrko
  • 1,720
  • 17
  • 22
0

httplib uses HTTP/1.1 (see HTTPConnection.putRequest method documentation).

Check httpResponse.version to see what version the server is using.

yotommy
  • 1,472
  • 1
  • 12
  • 17