Search code examples
pythonhttp-requestpython-requests

Using headers with the Python requests library's get method


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?


Solution

  • According to the API, the headers can all be passed in with requests.get():

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