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%.
@@ -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):
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
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
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).
- 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”
Failure Signature (Search String)
- self = <tests.test_requests.TestRequests object at 0x7f68030882b0>
Error Message
Stack trace
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
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
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.
When NOT to Use This Fix
- This fix is not applicable if using pytest versions prior to 5.
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 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
| Version | Status |
|---|---|
| 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.