Session object allows one to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance and will use urllib3’s connection pooling. So if several requests are being made to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase. A session object all the methods as of requests.
Using Session Objects
Let us illustrate use of session objects by setting a cookie to a url and then making a request again to check if cookie is set.
One can check that cookie was still set when the request was made again.
Sessions can also be used to provide default data to the request methods. This is done by providing data to the properties on a Session object:
- CBSE 12th class Paper Solved - 2015-16 session
- GET and POST requests using Python
- How to install requests in Python - For windows, linux, mac
- HEAD method - Python requests
- DELETE method- Python requests
- PUT method - Python requests
- PATCH method - Python requests
- POST method - Python requests
- GET method - Python requests
- Http Request methods - Python requests
- response.headers - Python requests
- response.encoding - Python requests
- response.elapsed - Python requests
- response.close() - Python requests
- response.content - Python requests
- response.cookies - Python requests
- response.history - Python requests
- response.is_permanent_redirect - Python requests
- response.is_redirect - Python requests
- response.iter_content() - Python requests
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.