'Equivalent of 'curl --cookie-jar' for Python's requests library

I would like to know how to do the equivalent of this:

curl --location --request POST "https://example.com/some/path" ... --cookie-jar "/Path/On/My/Computer"

Using Python's requests library. I tried something like this:

from http.cookiejar import CookieJar
import requests

jar = CookieJar()  # <-- the path should surely be set somehow, but unsure how

session = requests.session()
response = session.post("https://example.com/some/path", cookies=jar, ...)

Although I can't make it work, I keep getting a 403. It works when I try it with Insomnia (https://insomnia.rest/), so the credentials I'm sending are ok, but the cookie jar part is unclear to me. Any help would be very much appreciated, thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source