`http.client.HTTPSConnection._tunnel` raises `AttributeError: 'NoneType' object has no attribute 'encode'` when header value is `None`
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 68/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- python
- Domínio
- backend, networking
Direção de pesquisa
Comece lendo http.client.HTTPSConnection._tunnel e o tratamento de set_tunnel em Lib/http/client.py; compare o comportamento com a versão 3.10.20 identificada no relatório. Confira os testes de túnel existentes em Lib/test/test_httplib.py e adicione cobertura para um valor de cabeçalho None. A tarefa estará concluída quando a regressão estiver coberta e _tunnel() não travar mais com essa entrada.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 77.6k
- Forks
- 37.6k
- Merge médio
- 1d 10h
- PRs com merge (30d)
- 573
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/cpython
-
A minor problem with the section "6.10.2. Membership test operations" from the language reference.Abertadocs
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia
-
docs
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 78/100
python/cpython#159012 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
stdlib topic-profiling type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
stdlib type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
lazy import of `_sysconfig` in `Lib/ctypes/__init__.py` is eager on android and cygwinTalvez já em andamento @sillyfellow21 assumiu há 4 dias. Abertatests topic-lazy-imports
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
python/cpython#158684 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/cpython
Issues semelhantes
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
Deepak3699/Ai_Mentor#244 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
btclib-org/btclib-node#1880 ·
Mantenedores costumam responder em até 1 dia
-
CONTRIBUTING.md: say how ticketless bug fixes and feature PRs are handledTalvez já em andamento @khuisman assumiu hoje. Abertav0.9.2
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 84/100
khuisman/mcp-gee-sweet#941 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
pyjanitor-devs/pyjanitor#1758 ·
Mantenedores costumam responder em até 1 dia
-
bug ready for review
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 86/100
odysseus-dev/odysseus#6641 ·
Mantenedores costumam responder em até 1 dia