Search code examples
pythonurllib3

How do you use cookiejar with urllib3?


How do you use cookiejar with urllib3?

According to Python urllib3 and how to handle cookie support? from 2010 it wasn't supported then. However, in the change log for urllib3 1.22 (2017-07-20) there's mention of a compatibility fix for cookiejar.

Fixed compatibility for cookiejar. (Issue #1229)

So it sounds like some support has been added. But I have been unable to find any mention about cookiejar or even cookies in urllib3's documentation.


Solution

  • According to the test suite, CookieJar's extract_cookies method can be used to populate a CookieJar from an instance of urllib3's HTTPResponse class:

    cookiejar.extract_cookies(response, request)