Skip to content

Fix AttributeError when response body is StreamingBody in error response handling#3683

Closed
armorbreak001 wants to merge 1 commit intoboto:developfrom
armorbreak001:fix/streaming-body-strip-error
Closed

Fix AttributeError when response body is StreamingBody in error response handling#3683
armorbreak001 wants to merge 1 commit intoboto:developfrom
armorbreak001:fix/streaming-body-strip-error

Conversation

@armorbreak001
Copy link
Copy Markdown

Description

Fixes #4754

When an S3-compatible service (e.g., Wasabi) returns a 5xx error, the error handling path in _is_generic_error_response calls .strip() on the response body. When checksum validation is enabled (default since 1.36.0), the response body is wrapped in a StreamingChecksumBody (or StreamingBody) object, which does not have a .strip() method. This causes an AttributeError that masks the original server error.

Changes

Read the body content via .read() if it is a file-like object before calling .strip(). This handles both StreamingChecksumBody, StreamingBody, and regular bytes/string bodies without affecting existing behavior for non-streaming responses.

Testing

  • Existing test suite passes (83 tests in test_parsers.py)
  • The fix is minimal and defensive — only activates when body has a read() method

…ic_error_response

When a streaming body wrapper (StreamingChecksumBody or StreamingBody)
is used as the response body, calling .strip() directly raises
AttributeError because these objects don't have a strip method.
Read the body content first if it's a file-like object before
calling strip().
@armorbreak001
Copy link
Copy Markdown
Author

Duplicate of #3680 (already open, fixes same issue).

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.

1 participant