The Fix
Upgrade to version 0.13.0 or later.
Based on closed encode/httpx issue #530 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -48,7 +48,7 @@ def __init__(
self.name = name
if not isinstance(value, tuple):
- self.filename = Path(getattr(value, "name", "upload")).name
+ self.filename = Path(str(getattr(value, "name", "upload"))).name
self.file = value # type: typing.Union[typing.IO[str], typing.IO[bytes]]
venv/lib/python3.7/site-packages/httpx/client.py:484: in post
trust_env=trust_env,
venv/lib/python3.7/site-packages/httpx/client.py:616: in request
cookies=cookies,
venv/lib/python3.7/site-packages/httpx/client.py:356: in build_request
cookies=cookies,
venv/lib/python3.7/site-packages/httpx/models.py:696: in __init__
content, content_type = self.encode_data(data, files, json)
venv/lib/python3.7/site-packages/httpx/models.py:619: in encode_data
content, content_type = multipart_encode(data or {}, files)
venv/lib/python3.7/site-packages/httpx/multipart.py:100: in multipart_encode
for field in iter_fields(data, files):
venv/lib/python3.7/site-packages/httpx/multipart.py:93: in iter_fields
yield FileField(name=name, value=value)
venv/lib/python3.7/site-packages/httpx/multipart.py:51: in __init__
self.filename = Path(getattr(value, "name", "upload")).name
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py:994: in __new__
self = cls._from_parts(args, init=False)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py:649: in _from_parts
drv, root, parts = self._parse_args(args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'pathlib.PosixPath'>, args = (29,)
@classmethod
def _parse_args(cls, args):
# This is useful when you don't want to create an instance, just
# canonicalize some constructor arguments.
parts = []
for a in args:
if isinstance(a, PurePath):
parts += a._parts
else:
a = os.fspath(a)
E TypeError: expected str, bytes or os.PathLike object, not int
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.13.0 or later.\nWhen NOT to use: This fix is not applicable if the file handling logic requires the original integer behavior.\n\n
Why This Fix Works in Production
- Trigger: Instances of `tempfile.TemporaryFile` fail when used as an upload file.
- Mechanism: Fixes the issue where instances of `tempfile.TemporaryFile` fail when used as an upload file by ensuring the filename is properly converted to a string.
- Why the fix works: Fixes the issue where instances of `tempfile.TemporaryFile` fail when used as an upload file by ensuring the filename is properly converted to a string. (first fixed release: 0.13.0).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.7 in real deployments (not just unit tests).
- Production symptom (often without a traceback): Instances of `tempfile.TemporaryFile` fail when used as an upload file.
Proof / Evidence
- GitHub issue: #530
- Fix PR: https://github.com/encode/httpx/pull/545
- First fixed release: 0.13.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.35
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“When using tempfile.TemporaryFile the file.name attribute returns an integer, rather than the usual path string, which causes a breakage for us further down the line... Have also confirmed that the issue *doesn't* occur with tempfile.NamedT”
Failure Signature (Search String)
- Instances of `tempfile.TemporaryFile` fail when used as an upload file.
- E TypeError: expected str, bytes or os.PathLike object, not int
Copy-friendly signature
Failure Signature
-----------------
Instances of `tempfile.TemporaryFile` fail when used as an upload file.
E TypeError: expected str, bytes or os.PathLike object, not int
Error Message
Signature-only (no traceback captured)
Error Message
-------------
Instances of `tempfile.TemporaryFile` fail when used as an upload file.
E TypeError: expected str, bytes or os.PathLike object, not int
Minimal Reproduction
venv/lib/python3.7/site-packages/httpx/client.py:484: in post
trust_env=trust_env,
venv/lib/python3.7/site-packages/httpx/client.py:616: in request
cookies=cookies,
venv/lib/python3.7/site-packages/httpx/client.py:356: in build_request
cookies=cookies,
venv/lib/python3.7/site-packages/httpx/models.py:696: in __init__
content, content_type = self.encode_data(data, files, json)
venv/lib/python3.7/site-packages/httpx/models.py:619: in encode_data
content, content_type = multipart_encode(data or {}, files)
venv/lib/python3.7/site-packages/httpx/multipart.py:100: in multipart_encode
for field in iter_fields(data, files):
venv/lib/python3.7/site-packages/httpx/multipart.py:93: in iter_fields
yield FileField(name=name, value=value)
venv/lib/python3.7/site-packages/httpx/multipart.py:51: in __init__
self.filename = Path(getattr(value, "name", "upload")).name
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py:994: in __new__
self = cls._from_parts(args, init=False)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py:649: in _from_parts
drv, root, parts = self._parse_args(args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'pathlib.PosixPath'>, args = (29,)
@classmethod
def _parse_args(cls, args):
# This is useful when you don't want to create an instance, just
# canonicalize some constructor arguments.
parts = []
for a in args:
if isinstance(a, PurePath):
parts += a._parts
else:
a = os.fspath(a)
E TypeError: expected str, bytes or os.PathLike object, not int
Environment
- Python: 3.7
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.13.0 or later.
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/encode/httpx/pull/545
First fixed release: 0.13.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the file handling logic requires the original integer behavior.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.13.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.