Non-string form field names raise AttributeError when files are attached
@nightcityblade is already working on this.
Since Oct 12, 2026.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- backend-api-design
Research direction
Start in requests/models.py at _encode_files, where the issue identifies RequestField(name=k, ...), and inspect the nearby multipart preparation tests. Reproduce with the provided requests.Request examples using non-string keys in data and files. Done when multipart preparation handles both cases as expected or raises a TypeError naming the field, with tests covering the behavior.
Written by the indexing model from the issue text.
Description
While testing an experimental version of Perch, we found the following and figured it was worth a report.
A non-string key in data works for a urlencoded body, but the same data fails once files is added and the body becomes multipart. A non-string key in files fails the same way.
Expected Result
The request prepares in both cases (the urlencoded path already accepts {1: "a"} and sends 1=a), or a TypeError that names the field.
Actual Result
AttributeError: 'int' object has no attribute 'translate'
raised from inside urllib3. _encode_files passes the field name straight to RequestField(name=k, ...) (models.py:245), which expects a str. Values are converted with str() a few lines earlier; names aren't.
Reproduction Steps
import requests
requests.Request("POST", "http://x", data={1: "a"}).prepare()
# works
requests.Request("POST", "http://x", data={1: "a"}, files={"f": b"x"}).prepare()
# AttributeError: 'int' object has no attribute 'translate'
requests.Request("POST", "http://x", files={1: b"x"}).prepare()
# AttributeError: 'int' object has no attribute 'translate'
System Information
$ python -m requests.help
{
"chardet": {
"version": null
},
"charset_normalizer": {
"version": "3.5.2"
},
"cryptography": {
"version": ""
},
"idna": {
"version": "3.20"
},
"implementation": {
"name": "CPython",
"version": "3.14.2"
},
"platform": {
"release": "25.2.0",
"system": "Darwin"
},
"pyOpenSSL": {
"openssl_version": "",
"version": null
},
"requests": {
"version": "2.34.2"
},
"system_ssl": {
"version": "30500040"
},
"urllib3": {
"version": "2.8.0"
},
"using_charset_normalizer": true,
"using_pyopenssl": false
}
- Dominant language
- Python
- Stars
- 54.5k
- Forks
- 12.9k
- Avg merge
- 3h 26m
- 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 72/100
-
TestTimeout abandons three delay/10 requests and later tests wait out the serverPossibly taken @hananbahi527 claimed this 3 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Incorrect type annotation for iter_linesMay be free again @nightcityblade claimed this 23 days ago, and no pull request is open. Open
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
proxy_bypass_registry uses unanchored re.match (Windows proxy bypass)May be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Docstring examples in `from_key_val_list` show the pre-3.12 OrderedDict reprMay be free again @Abirami-26 claimed this 22 days ago, and no pull request is open. Open
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sierra-research/tau2-bench#635 ·
Maintainers usually reply within 1 day
-
The add-ssm-model skill requires a Cython simulator; the contributing guide allows Python onesPossibly taken @fmuia claimed this today. Opendocumentation skill
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
lnccbrown/ssm-simulators#406 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 Under an hour Newbie friendliness 95/100
btclib-org/btclib-ecc#309 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
jbacalso24/mimry#459 · 1 comment ·
Maintainers usually reply within 1 day
-
[Bug] POST /revoke with a FastMCP access token is a silent no-op (ownership gate never matches)Openauth bug high-priority
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day