Skip to content

Commit

Permalink
OPS: fix EscherRequest for empty PreparedRequest body
Browse files Browse the repository at this point in the history
Co-authored-by: Laszlo Losonczy <[email protected]>
  • Loading branch information
knagy and losonczylaci committed Mar 14, 2024
1 parent e91b871 commit 09cbc28
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions escherauth/escherauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def body(self):
if self.is_presigned_url:
return 'UNSIGNED-PAYLOAD'
if self.type is requests.models.PreparedRequest:
return self.request.body.decode('utf-8') or None
if isinstance(self.request.body, bytes):
return self.request.body.decode('utf-8')
else:
return self.request.body or ''
if self.type is dict:
return self.request.get('body')

Expand Down Expand Up @@ -369,7 +372,7 @@ def canonicalize(self, req, headers_to_sign):
self.canonicalize_headers(req.headers(), headers_to_sign),
'',
self.prepare_headers_to_sign(headers_to_sign),
self.algo(req.body().encode('utf-8')).hexdigest()
self.algo((req.body() or '').encode('utf-8')).hexdigest()
])

def canonicalize_path(self, path):
Expand Down

0 comments on commit 09cbc28

Please sign in to comment.