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.
If you want to change the referer (url) header that will be sent to the server when a user clicks an anchor or iframe is opened, you can do it without any hacks. Simply do history. replaceState, you will change the url as it will appear in the browser bar and also the referer that will be send to the server.
url returns the URL of the response. It will show the main url which has returned the content, after all redirections, if done. Python requests are generally used to fetch the content from a particular resource URI. Whenever we make a request to a specified URI through Python, it returns a response object.
It's available in the HTTP referer header. You can get it in a servlet as follows: String referrer = request. getHeader("referer"); // Yes, with the legendary misspelling.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With