What is the difference between request and request. Session()?

Asked

Viewed 552 times

0

I would like to know the difference between request and request. Session() of the request module.

What would be the ideal use of each?

1 answer

2

Requests is a simple and elegant HTTP library for Python, made for humans. You are now viewing the development version documentation.

The Session() allows you to persist some parameters through requests. It also allows cookie persistence through all requests made from a Session instance.

Example of persistence of some cookies through requests:

    s = requests.Session()

    s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')
    r = s.get("http://httpbin.org/cookies")

    print r.text
    # '{"cookies": {"sessioncookie": "123456789"}

So to sum up, the requeste is the library and the Session() is the object of this library used for cookie persistence. You can read more about here, in case I have more questions about

Browser other questions tagged

You are not signed in. Login or sign up in order to post.