views:

48

answers:

4

i can make get or post request using urllib.

how do i make delete and put requests?

+1  A: 

The method is set implicitly in the urlopen call

When you provide the data parameter a POST will be used.

urllib.request.urlopen(url, data=None[, timeout])

I don't think it's possible to use a DELETE HTTP method with urlib because of this line:

Request.get_method()
Return a string indicating the HTTP request method. This is only meaningful for HTTP requests, and currently always returns 'GET' or 'POST'.

Consider using httplib, httplib2, or Twisted instead .for better support of HTTP methods.

Brian R. Bondy
+1  A: 

PUT request can be performed by httplib2

http://code.google.com/p/httplib2

yedpodtrzitko
thanks, delete can be done with this too
kevin
+1  A: 

http://twistedmatrix.com/documents/current/web/howto/client.html

If you're looking to work with HTTP in twisted using the client side I'd suggest checking that out. It demonstrates how you can really easily make a request using the agent class.

themaestro
A: 

As far as I know, urllib and urllib2 only support GET and POST requests. You should probably take a look at httplib or httplib2.

Luke404