Custom request headers in Python

Just to be fair, here’s the same example in Python, batteries included.

#!/usr/bin/python

import httplib

conn = httplib.HTTPConnection('digitaltorque.ca')
params = {}
headers = { 'X-Bender': 'Bite my shiny metal ass!' }

conn.request("GET", "/", params, headers)

response = conn.getresponse()

print response.read()

Not too painful.

Advertisements

Post a Comment

Required fields are marked *

*
*

%d bloggers like this: