Repository navigation
Make the urllib3 POST test send its form fields - #1059
Merged
Merged
Conversation
Since urllib3 2.0, the third positional argument of request() is the body, not the form fields, so test_post passed its dict as the body. urllib3 then sent the dict's keys as a chunked body, which the local httpbin server answers with a 501 without reading it. The test only compared the recorded and replayed responses, so it kept passing, except when the server closed the connection while urllib3 was still sending: it then failed with BrokenPipeError, in 9 of 100 runs on CPython 3.13 and 4 of 100 on 3.14 here. Pass the form as fields=data, and check that httpbin echoes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
cclauss
approved these changes
Oct 18, 2026
cclauss
left a comment
Contributor
There was a problem hiding this comment.
@kevin1024 Please approve the GitHub Actions test runs to see if they pass.
Contributor
Author
|
@kevin1024 @cclauss Friendly ping: could this be merged, or is anything still needed from my side? Thanks! |
# Conflicts: # docs/changelog.rst
Owner
|
This has been released in v8.4.0. Thanks @pylaterreur! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_postintests/integration/test_urllib3.pyfails now and then withBrokenPipeError: in my runs, 9 times in 100 on CPython 3.13 and 4 in 100 on 3.14. It's a test bug: since urllib3 2.0, the third positional argument ofrequest()is the body, not the form fields.request()signaturerequest(method, url, fields=None, ...)request(method, url, body=None, fields=None, ...)urllib3-future, which the niquests jobs use, has the 2.x signature.
So
verify_pool_mgr.request("POST", url, data)sends the dict as the body. urllib3 iterates it and sends its keys as a chunked body, which httpbin answers with a 501 without reading it. The test only compared the recorded and replayed responses, so it kept passing on two identical 501s, except when the server closed the connection while urllib3 was still sending.Fix
Pass the form as
fields=data, as the test meant to, and check that httpbin echoes it, so the test fails if the form stops being sent.Tests
test_post(http and https) passes on CPython 3.13.16, 3.14.8 and 3.15.0rc2 with urllib3 2.8.0. It also passes on 3.15.0rc2 with urllib3-future 2.25.901, with and without Fix niquests connection reuse with urllib3-future 2.25.901 #1056.test_post100 times per version, under the same load, in a network namespace like CI's offline step:test_postpasses in all of them. The failing jobs are thetests-niquestsones, fixed by Fix niquests connection reuse with urllib3-future 2.25.901 #1056, andpypy-3.11, because of a tornado bug on PyPy 8.0. iostream: Release memoryviews explicitly for PyPy 8.0 compatibility tornadoweb/tornado#3750 fixed it, but the fix isn't released yet (see Support Python 3.14 and 3.15, test free-threaded builds in CI #1058).pre-commit run --all-filesand codespell: clean.Three other tests fail the same way:
test_post_chunked_binary,test_body_consumed_once_iteratorandtest_body_consumed_once_stream. They send chunked bodies on purpose, so they need pytest-httpbin's server to handle them: kevin1024/pytest-httpbin#101.🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN