(snippet) Peticiones PUT y DELETE con urllib2

Written by Samuel de Ancos

Os presento un sencilla receta para implementar peticiones PUT y DELETE con la libreria urllib2 de python:

import urllib2

opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request("localhost")

# Metodo Put
request.get_method = lambda: "PUT"

# Metodo Delete
request.get_method = lambda: "DELETE"

response = opener.open(request)