Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

`http.client.HTTPSConnection._tunnel` raises `AttributeError: 'NoneType' object has no attribute 'encode'` when header value is `None`

Aberta Para iniciantes
#159,044 4 comentários 0 reações 0 responsáveis Ver no GitHub

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

stdlib type-bug
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

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.