A tweaked version of urllib2.Request that accepts an HTTP method as a parameter.
Created: 2006-04-07 | Updated: 2006-04-07 | Status: Complete | Tags: python
I was working on retrieving mailbox storage statistics from Microsoft Exchange and needed to make a WebDAV request with the HTTP SEARCH method. Python's extensive web-related programming libraries surprisingly don't directly offer setting the request method. However, it was trivial to cook up the following "enhanced" Request class:
import urllib2
class Request(urllib2.Request):
def __init__(self, url, method='GET', data=None, headers={},
origin_req_host=None, unverifiable=False):
urllib2.Request.__init__(self, url, data, headers,
origin_req_host, unverifiable)
self.method = method
def get_method(self):
return self.method.upper()
if __name__ == '__main__':
req = Request('http://projects.dowski.com/', 'HEAD')
resp = urllib2.urlopen(req)
print resp.headers
balloondemo
brockman
buffet
buffetmyghty
buffetstring
buffetxslt
cardinfo
cp22collection
cp22simple_ajax
cp_middleware_server
cpmyghty
excuses
iresponse
littlebrother
multiauth
phpfilter
pysourcecolorfilter
request2
simplebackend
stunnelfilter
wsgi_filter
wireless
wsgi
http
templating
cherrypy
ssl
python
plugins
module
win32
application
ajax
library
cheetah
myghty
filter
kid