Jump to solution
Verify

The Fix

pip install requests==2.27.0

Based on closed psf/requests issue #5304 · 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
@@ -774,8 +774,10 @@ def __len__(self): url = httpbin('post') with open('Pipfile') as f: - pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})") - pytest.raises(ValueError, "requests.post(url, data=u('[{\"some\": \"data\"}]'), files={'some': f})") + with pytest.raises(ValueError):
repro.py
self = <tests.test_requests.TestRequests object at 0x7f68030882b0> httpbin = <function prepare_url.<locals>.inner at 0x7f68034c8f70> def test_conflicting_post_params(self, httpbin): url = httpbin('post') with open('Pipfile') as f: pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})") E TypeError: 'requests.post(url, data=\'[{"some": "data"}]\', files={\'some\': f})' object (type: <class 'str'>) must be callable tests/test_requests.py:777: TypeError
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 is not applicable if using pytest versions prior to 5.\n\n

Why This Fix Works in Production

  • Trigger: self = <tests.test_requests.TestRequests object at 0x7f68030882b0>
  • Mechanism: Fixes the test_conflicting_post_params to work with pytest 5 by replacing the non-contextmanager form of pytest.raises with the context manager form.
  • Why the fix works: Fixes the test_conflicting_post_params to work with pytest 5 by replacing the non-contextmanager form of pytest.raises with the context manager form. (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

  • Surfaces as: self = <tests.test_requests.TestRequests object at 0x7f68030882b0>

Proof / Evidence

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

Discussion

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

“https://github.com/psf/requests/pull/5305”
@hroncok · 2020-01-02 · source

Failure Signature (Search String)

  • self = <tests.test_requests.TestRequests object at 0x7f68030882b0>

Error Message

Stack trace
error.txt
Error Message ------------- self = <tests.test_requests.TestRequests object at 0x7f68030882b0> httpbin = <function prepare_url.<locals>.inner at 0x7f68034c8f70> def test_conflicting_post_params(self, httpbin): url = httpbin('post') with open('Pipfile') as f: pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})") E TypeError: 'requests.post(url, data=\'[{"some": "data"}]\', files={\'some\': f})' object (type: <class 'str'>) must be callable tests/test_requests.py:777: TypeError

Minimal Reproduction

repro.py
self = <tests.test_requests.TestRequests object at 0x7f68030882b0> httpbin = <function prepare_url.<locals>.inner at 0x7f68034c8f70> def test_conflicting_post_params(self, httpbin): url = httpbin('post') with open('Pipfile') as f: pytest.raises(ValueError, "requests.post(url, data='[{\"some\": \"data\"}]', files={'some': f})") E TypeError: 'requests.post(url, data=\'[{"some": "data"}]\', files={\'some\': f})' object (type: <class 'str'>) must be callable tests/test_requests.py:777: 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 is not applicable if using pytest versions prior to 5.

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/5305

First fixed release: 2.27.0

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if using pytest versions prior to 5.

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

  • Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
  • Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.

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.