Q:

Post method with Requests

I'm trying to make a simple post method with the requests module, like this :
 s=requests. Session() 

 s.post(link,data=payload)

In order to do it properly, the payload is an id from the page itself, and it's generated in every access to the page. 
So I need to get the data from the page and then proceed the request. 
The problem when you accessed the page is that a new id will be generated. 
So if we do this: 
 s=requests. Session() 

 payload=get_payload(s.get(link).text)

 s.post(link,data=payload)

It will not work because when you acceded the page with s.get the right id is generated, but when you go for the post request, a new id will be generated so you'll be using an old one. 
Is there any way to get the data from the page right before the post request?  
Something like: 
 s.post(link,data=get_data(s.get(link))

A:

When you do a post (or get) request, the page will generate another id and send it back to you.  There is no way of sending data to the page while it is being generated because you need to receive a response first to process the data on the page and once you have received the response, the server will create a new id for you the next time you view the page. 
See https://www3.ntu.edu.sg/home/ehchua/programming/webprogramming/images/HTTP.png for a simple example image of a HTTP Request

