Skip to content

Handle empty responses without a content type - #402

Open
blouirts123 wants to merge 1 commit into
requests:mainfrom
blouirts123:fix/empty-multipart-response
Open

blouirts123 wants to merge 1 commit into
requests:mainfrom
blouirts123:fix/empty-multipart-response

Conversation

@blouirts123

Copy link
Copy Markdown

Fixes #345. A response with content == b'' and no Content-Type currently raises AttributeError before MultipartDecoder.from_response() can return a decoder.

Return an empty parts tuple for that exact case and preserve the supplied encoding. Nonempty bodies without a Content-Type keep their existing behavior, as do explicit invalid content types and empty multipart bodies with a valid boundary. This addresses the empty-response handling requested in #345; #399 covers a different missing-boundary case.

Validation: 19 decoder tests pass. Full strict-warning suites pass on Python 3.8–3.11 (171 passed, 5 skipped each) with PyOpenSSL 24.2.1 in the local environments. With the latest resolved PyOpenSSL 26.4.0, both candidate and unchanged base fail the same two X509 adapter tests on dependency deprecation warnings. No dependency pin is added. Ordinary flake8 passes; the docstrings plugin reports the same 171 findings on both trees. The Sphinx HTML build succeeds with one theme deprecation warning. PyPy 2.7.18 also passes all 19 decoder tests using pytest 3.5.1 and compatible legacy dependencies; PyOpenSSL was unavailable there, and its two tests use the existing project skip condition. Its full strict-warning suite reports 167 passed, 7 skipped, and the same two Windows TCP-keepalive strict XPASS failures as the unchanged base (162 passed, 7 skipped, same two failures). Python 3.7 was not run locally.

An empty response can omit Content-Type, causing multipart decoding to
fail before callers can inspect its parts. Return an empty tuple only
for that exact case, preserving other validation and the encoding.

Add regression and behavior-preservation tests and document the case.

Closes requests#345.
@blouirts123
blouirts123 marked this pull request as draft October 16, 2026 04:52
@blouirts123
blouirts123 marked this pull request as ready for review October 16, 2026 05:25
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.

Sending a zero-part multipart document has an uncaught exception; .parts should be an empty list instead

1 participant