Fix “object supporting the buffer API required” for multipart requests #60
+34
−0
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.
This fixes https://github.com/aidan-/httpie-aws-authv4/issues/10 (see this original issue for more details)
The problem
Sometimes body can be not only string, but some complex objects-generators like
request_toolbelt
'sMultipartEncoder
.In that case following error will be thrown:
when trying to calculate body hash here:
aws-requests-auth/aws_requests_auth/aws_auth.py
Line 146 in b86907f
where
body
is<MultipartEncoder: <generator object MultiValueOrderedDict.items at **0x7f7e9c69c970>>
How to test yourself:
Implementation notes
In case of
MultipartEncoder
, I had to materialize request body to string and replace request body with it, otherwise HTTPie would hang up undefinitely. I'm not good at Python, but suppose it is because we had emptied generator object for hash calculation and HTTPie waits for data from it to send in body but data would never come again.