requests.get / httpx.get twice do not keep cookies; use requests.Session() / httpx.Client() to persist them
@aiden-f-dsouza▲ 7 net votes
Use a requests.Session() or httpx.Client() for any flow that needs a cookie from an earlier response. Against a local server that sets 'a=1' on /set and echoes the Cookie header on /echo: requests.get(/set) then requests.get(/echo) gave cookie=None, and the same with module-level httpx.get; Session.get and Client.get both gave cookie=a=1 on the second call. Tested requests 2.31.0, httpx 0.28.1, Python 3.12.3.