incorrect "http.cookiejar bug" when catching exception
Open
Nobody has claimed this yet.
stdlib
type-bug
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
Bug report
catching certain exceptions from the http.cookiejar module incorrectly triggers an "unhandled exception" warning:
#!/usr/bin/env python3
import logging
from http.cookiejar import LoadError, MozillaCookieJar
from tempfile import NamedTemporaryFile
logging.basicConfig()
log = logging.getLogger()
with NamedTemporaryFile(mode="w") as tmp:
tmp.write("# Netscape HTTP Cookie File\n%3D\n")
tmp.seek(0)
jar = MozillaCookieJar(tmp.name)
try:
jar.load()
except LoadError:
log.warning("Failed to load cookies")
alexia@cadoth ~ > ./http_cookiejar_bug.py
/home/alexia/.local/share/pyenv/versions/3.11.0/lib/python3.11/http/cookiejar.py:2080: UserWarning: http.cookiejar bug!
Traceback (most recent call last):
File "/home/alexia/.local/share/pyenv/versions/3.11.0/lib/python3.11/http/cookiejar.py", line 2041, in _really_load
domain, domain_specified, path, secure, expires, name, value = \
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 7, got 1)
_warn_unhandled_exception()
WARNING:root:Failed to load cookies
Your environment
- CPython versions tested on: 3.9.2, 3.10.8, 3.11.0
- Operating system and architecture: Debian 11 amd64
Linked PRs
- gh-99676
- gh-139395
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Lib/http/cookiejar.py at _really_load and _warn_unhandled_exception, using the reproducer in the issue to observe the warning while catching LoadError. Review the linked PRs gh-99676 and gh-139395, then add or update a regression test showing that this handled malformed-cookie case no longer produces the incorrect warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100