Bug report
LWPCookieJar.save() doesn't truncate the file.
So removing cookies from an existing jar file then saving it gives unexpected results :
from http.cookiejar import LWPCookieJar
from urllib.request import Request, urlopen
lwp = LWPCookieJar("cookies.lwp")
# get some cookies & save
request = Request("https://www.scoopmeacookie.com/give-me-more/")
with urlopen(request) as response:
lwp.extract_cookies(response, request)
# here's some cookies
print(f"Extracted : {lwp}")
lwp.save()
# clear the jar & save
lwp.clear()
# the jar is now empty
print(f"Clear : {lwp}")
lwp.save()
# are those cookies really gone ?
lwp.load()
# they're back ! that would be great IRL
# LWPCookieJar.save() didn't truncate the file (os.O_TRUNC is missing)
print(f"Reload : {lwp}")
Environment
- Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]
- Windows 10 64 bits 22H2
Linked PRs
Reactions are currently unavailable
Bug report
LWPCookieJar.save() doesn't truncate the file.
So removing cookies from an existing jar file then saving it gives unexpected results :
Environment
Linked PRs