Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What's the difference between requests.get ( ) and requests.session ( )?


Asked by Adelyn Walls on Dec 10, 2021 FAQ



Under the hood, requests.get() creates a new Session object for each request made. By creating a session object up front, you get to reuse the session; this lets you persist cookies, for example, and lets you re-use settings to be used for all connections such as headers and query parameters.
In respect to this,
Request is something which comes in handy when you are moving from one page to another by submitting a form. Whereas session is something that exists unless you explicitely remove it or the browser gets closed. the diff between...
Thereof, Request attribute is only available in the request object lifetime. filters, servlet, jsp, include, forward uses same request object. Once the request is completed, request object is destroyed. Whereas session attributes are available till the session ends or till the browser is closed. Hence the difference lies in the scope.
Just so,
request.getSession (true) will return current session. If current session does not exist, then it will create a new session. So basically there is not difference between both method. request.getSession (false) will return current session if current session exists, then it will not create a new session.
Consequently,
As nouns the difference between request and requests is that request is act of (l) while requests is . is to express the need or desire for.