I am using requests.get()
to get data back from an API, however, I must include cookies or else the request will not return data. The idea is to include it as a part of the headers parameters however I can only get cookies **after **the request has been made. I need to get the cookies **before **the actual request and include in the request I am making as a part of the parameters.
I have started off by creating a new session:session = requests.Session()
Then making the request:response = session.get('http://google.com')
My problem however is that I should Have the cookies before using .get()
and add the cookies as a parameter in headers or else the API request fails. I am aware of the method to obtain the cookies after the request using:session.cookies.get_dict()
The site I am getting data from generates cookies at random every 2 minutes so I need to be able to grab that string plug it into my .get()
above.
Thanks!