`http.client.HTTPSConnection._tunnel` raises `AttributeError: 'NoneType' object has no attribute 'encode'` when header value is `None`
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 68/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend, networking
Línea de trabajo
Empieza leyendo http.client.HTTPSConnection._tunnel y el manejo de set_tunnel en Lib/http/client.py; compara el comportamiento con la versión 3.10.20 indicada en el informe. Revisa las pruebas existentes del túnel en Lib/test/test_httplib.py y añade cobertura para un valor de encabezado de None. La tarea estará completa cuando la regresión esté cubierta y _tunnel() ya no se bloquee con esa entrada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug report
Bug Description
Calling http.client.HTTPSConnection._tunnel() raises AttributeError: 'NoneType' object has no attribute 'encode' when _tunnel_headers contains a header key with a None value.
This regression affects third-party libraries (such as Apache Thrift and CodeChecker) that pass header dictionaries containing None values into set_tunnel(..., headers=...) or HTTP connection objects.
In Python 3.10.21, _tunnel() introduced strict encoding of tunnel headers (value.encode("latin-1")) without checking if the header value is None.
Target Python Version
Python 3.10.21 (Regression introduced between 3.10.20 and 3.10.21)
Operating System
Linux / Ubuntu
Code to Reproduce
import http.client
conn = http.client.HTTPSConnection("127.0.0.1", 8080)
# Set tunnel with a header value of None
conn.set_tunnel("example.com", 443, headers={"X-Test-Header": None})
# Call _tunnel() to trigger the issue
conn._tunnel()
Expected Behavior
_tunnel() should gracefully handle or filter out header keys with None values (or handle string conversions) rather than crashing with an AttributeError.
Actual Behavior
Traceback (most recent call last):
File "reproduce.py", line 9, in
conn._tunnel()
File "/usr/lib/python3.10/http/client.py", line 936, in _tunnel
value_bytes = value.encode("latin-1")
AttributeError: 'NoneType' object has no attribute 'encode'
CPython versions tested on:
3.10
Operating systems tested on:
Linux
- Lenguaje dominante
- Python
- Estrellas
- 77.6k
- Forks
- 37.6k
- Merge medio
- 1 d 10 h
- PR fusionados (30 d)
- 573
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
A minor problem with the section "6.10.2. Membership test operations" from the language reference.Abiertodocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Docs: socket.htons() and friends raise ValueError for negative input since 3.14Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodocs
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
python/cpython#159012 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
stdlib topic-profiling type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
stdlib type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
lazy import of `_sysconfig` in `Lib/ctypes/__init__.py` is eager on android and cygwinPosiblemente ocupada @sillyfellow21 la tomó hace 5 días. Abiertotests topic-lazy-imports
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
python/cpython#158684 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
MystenLabs/MemWal#1163 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
infertopics leaves new nodes without a topic when untopiced neighbours outnumber topiced onesPosiblemente ocupada @moneebullah25 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
ClanGenOfficial/clangen#6254 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
FinanceFlash/unvibecode#218 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día