Changing the referer URL in python requests

PythonPython 2.7Python RequestsReferer

Python Problem Overview


How do I change the referer if I'm using the requests library to make a GET request to a web page. I went through the entire manual but couldn't find it.

Python Solutions


Solution 1 - Python

According to http://docs.python-requests.org/en/latest/user/advanced/#session-objects , you should be able to do:

s = requests.Session()
s.headers.update({'referer': my_referer})
s.get(url)

Or just:

requests.get(url, headers={'referer': my_referer})

Your headers dict will be merged with the default/session headers. From the docs:

> Any dictionaries that you pass to a request method will be merged with > the session-level values that are set. The method-level parameters > override session parameters.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMayank KumarView Question on Stackoverflow
Solution 1 - PythonsimonView Answer on Stackoverflow