Using headers with the Python requests library's get method

Breedly picture Breedly · Jun 7, 2011 · Viewed 304.3k times · Source

So I recently stumbled upon this great library for handling HTTP requests in Python; found here http://docs.python-requests.org/en/latest/index.html.

I love working with it, but I can't figure out how to add headers to my get requests. Help?

Answer

cwallenpoole picture cwallenpoole · Jun 7, 2011

According to the API, the headers can all be passed in using requests.get:

r=requests.get("http://www.example.com/", headers={"content-type":"text"})