0

I need to use a requests session object to set an HTTPAdaptor on the connection. I don't however want to actually track a session. That is, I don't wish to have cookies, or any other persistent data, stored and potentially sent with further requests.

Is there an easy way to disable this session tracking, or perhaps is there a way to use an HTTPAdapter without a session?

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267

1 Answers1

1

See this answer

the tl;dr is

from http import cookiejar  # Python 2: import cookielib as cookiejar
class BlockAll(cookiejar.CookiePolicy):
    return_ok = set_ok = domain_return_ok = path_return_ok = lambda self, *args, **kwargs: False
    netscape = True
    rfc2965 = hide_cookie2 = False

s = requests.Session()
s.cookies.set_policy(BlockAll())

s.get("https://httpbin.org/cookies/set?foo=bar")
assert not s.cookies
Community
  • 1
  • 1
Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91