Jump to solution
Verify

The Fix

pip install requests==2.27.0

Based on closed psf/requests issue #2844 · 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%.

Jump to Verify Open PR/Commit
@@ -81,7 +81,7 @@ def _encode_params(data): if isinstance(data, (str, bytes)): - return data + return to_native_string(data) elif hasattr(data, 'read'):
repro.py
import requests r = requests.get('http://python.org', params=b'test=foo') print(r.status_code)
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install requests==2.27.0\nWhen NOT to use: This fix should not be used if binary data needs to be uploaded through PUT.\n\n

Why This Fix Works in Production

  • Trigger: ... skip ...
  • Mechanism: The _encode_params function did not convert bytes to a native string, causing TypeError
  • Why the fix works: Fixes issue #2844 by modifying the _encode_params function to ensure that bytes are converted to a native string before returning. (first fixed release: 2.27.0).
Production impact:
  • 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.4 in real deployments (not just unit tests).
  • The _encode_params function did not convert bytes to a native string, causing TypeError
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

  • GitHub issue: #2844
  • Fix PR: https://github.com/psf/requests/pull/2845
  • First fixed release: 2.27.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-07
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.62

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“I think what we need to do here is to change encode_params to make sure that it calls to_native_string on its argument before returning it”
@Lukasa · 2015-10-23 · source
“This fix seems completely broken. It prevents me from uploading binary data through PUT.”
@untitaker · 2015-12-16 · source
“Could you release a quick 2.9.1 with this fix plz ? I was waiting the 2.9.0 for the REQUEST_CA_BUNDLE env var but cannot use it…”
@touilleMan · 2015-12-17 · source
“@touilleMan We're planning to release 2.9.1 on Monday.”
@Lukasa · 2015-12-17 · source

Failure Signature (Search String)

  • ... skip ...

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): ... skip ... url = requote_uri(urlunparse([scheme, netloc, path, None, query, fragment])) File "C:\Python35\lib\urllib\parse.py", line 383, in urlunparse _coerce_args(*components)) File "C:\Python35\lib\urllib\parse.py", line 111, in _coerce_args raise TypeError("Cannot mix str and non-str arguments") TypeError: Cannot mix str and non-str arguments

Minimal Reproduction

repro.py
import requests r = requests.get('http://python.org', params=b'test=foo') print(r.status_code)

Environment

  • Python: 3.4

What Broke

Requests with byte parameters resulted in TypeError, breaking functionality.

Why It Broke

The _encode_params function did not convert bytes to a native string, causing TypeError

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install requests==2.27.0

When NOT to use: This fix should not be used if binary data needs to be uploaded through PUT.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/psf/requests/pull/2845

First fixed release: 2.27.0

Last verified: 2026-02-07. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if binary data needs to be uploaded through PUT.

Verify Fix

verify
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

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Version Compatibility Table

VersionStatus
2.27.0 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.