Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Non-string form field names raise AttributeError when files are attached

Open Beginner friendly
#7,634 9 comments 0 reactions 0 assignees View on GitHub

@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

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from psf/requests

All issues in psf/requests

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.