incorrect "http.cookiejar bug" when catching exception
Aperta
Nessuno ha ancora preso questa issue.
stdlib
type-bug
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 36k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in Lib/http/cookiejar.py, in _really_load e _warn_unhandled_exception, usando il reproducer presente nell’issue per osservare l’avviso durante la cattura di LoadError. Esamina le PR collegate gh-99676 e gh-139395, quindi aggiungi o aggiorna un test di regressione che mostri che questo caso gestito di cookie malformato non produce più l’avviso errato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- networking
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100