get_encoding_from_headers treats any content type containing 'text' as text/* (ISO-8859-1)
@suyashgitt is already working on this.
Since Nov 13, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Read src/requests/utils.py and inspect get_encoding_from_headers, then look for tests covering that function. Reproduce the reported behavior with the application/vnd.context+xml, application/x-context, and application/jsonx media types. Done when only actual text/* types receive ISO-8859-1 and nonmatching types return None, with tests covering the cases.
Written by the indexing model from the issue text.
Description
Summary
requests.utils.get_encoding_from_headers uses substring checks on the media type, so non-text/* types that merely contain the letters "text" are treated as text and get ISO-8859-1.
In src/requests/utils.py:
if "text" in content_type:
return "ISO-8859-1"
Repro
from requests.utils import get_encoding_from_headers
from requests.structures import CaseInsensitiveDict as C
get_encoding_from_headers(C({"content-type": "application/vnd.context+xml"})) # 'ISO-8859-1'
get_encoding_from_headers(C({"content-type": "application/x-context"})) # 'ISO-8859-1'
Neither is a text/* type, so Response.encoding should be None (letting content-based detection run), not Latin-1. The same substring pattern is used for "application/json" in content_type, which would also match e.g. application/jsonx.
Suggested fix
Compare against the parsed media type, e.g. content_type.startswith("text/") and content_type == "application/json". Happy to open a PR with tests.
Checked on current main; I found no existing issue covering this.
- Dominant language
- Python
- Stars
- 54.7k
- Forks
- 10.8k
- Avg merge
- 18m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from psf/requests
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
-
`iter_lines(decode_unicode=True, delimiter=<str>)` raises `TypeError` when `Response.encoding` is `None`May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Invalid `params` type (e.g. int) raises misleading "TypeError: Cannot mix str and non-str arguments"Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
OCA/account-invoicing#2529 ·
Maintainers usually reply within 1 day
-
area/ci
Difficulty 1/5 Under an hour Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
ImageGen generate-batch aborts valid JSONL jobs containing a Unicode line separator in poster textOpenbug imagen skills
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Email validation accepts a trailing newlinePossibly taken @marcello-pichini claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day