Skip to content

Make the urllib3 POST test send its form fields - #1059

Merged
kevin1024 merged 2 commits into
kevin1024:masterfrom
pylaterreur:fix-urllib3-post-test
Oct 25, 2026
Merged

kevin1024 merged 2 commits into
kevin1024:masterfrom
pylaterreur:fix-urllib3-post-test

Conversation

@pylaterreur

@pylaterreur pylaterreur commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

test_post in tests/integration/test_urllib3.py fails now and then with BrokenPipeError: 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 of request() is the body, not the form fields.

request() signature
urllib3 1.26 request(method, url, fields=None, ...)
urllib3 2.0 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

Three other tests fail the same way: test_post_chunked_binary, test_body_consumed_once_iterator and test_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

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 cclauss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevin1024 Please approve the GitHub Actions test runs to see if they pass.

@pylaterreur

Copy link
Copy Markdown
Contributor Author

@kevin1024 @cclauss Friendly ping: could this be merged, or is anything still needed from my side? Thanks!

@kevin1024
kevin1024 merged commit 6cdccd5 into kevin1024:master Oct 25, 2026
12 checks passed
@pylaterreur
pylaterreur deleted the fix-urllib3-post-test branch October 25, 2026 15:10
@kevin1024

Copy link
Copy Markdown
Owner

This has been released in v8.4.0. Thanks @pylaterreur!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants