Bug report
LWPCookieJar.save() doesn't truncate the file.
So removing cookies from an existing jar file then saving it gives unexpected results :
fromhttp.cookiejarimportLWPCookieJarfromurllib.requestimportRequest, urlopenlwp=LWPCookieJar("cookies.lwp")
# get some cookies & saverequest=Request("https://www.scoopmeacookie.com/give-me-more/")
withurlopen(request) asresponse:
lwp.extract_cookies(response, request)
# here's some cookiesprint(f"Extracted : {lwp}")
lwp.save()
# clear the jar & savelwp.clear()
# the jar is now emptyprint(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
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