From cc9f0f9077b249e50497418eddf99b3e492945d9 Mon Sep 17 00:00:00 2001 From: Li Jiajia Date: Mon, 15 Dec 2025 16:21:27 +0800 Subject: [PATCH 1/2] fix(rest): handle empty body in AWS SigV4 signing --- pyiceberg/catalog/rest/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pyiceberg/catalog/rest/__init__.py b/pyiceberg/catalog/rest/__init__.py index 3b77fd47f0..7955c3320f 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -422,7 +422,14 @@ def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None: # pylin params = dict(parse.parse_qsl(query)) # remove the connection header as it will be updated after signing - del request.headers["connection"] + if "connection" in request.headers: + del request.headers["connection"] + # For empty bodies, explicitly set the content hash header to the SHA256 of an empty string + body = request.body + if body in (None, b"", ""): + request.headers["x-amz-content-sha256"] = ( + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + ) aws_request = AWSRequest( method=request.method, url=url, params=params, data=request.body, headers=dict(request.headers) From 750b14b80af226881989a6651c9421ac6e0c6672 Mon Sep 17 00:00:00 2001 From: Li Jiajia Date: Mon, 15 Dec 2025 16:47:54 +0800 Subject: [PATCH 2/2] fix format. --- pyiceberg/catalog/rest/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pyiceberg/catalog/rest/__init__.py b/pyiceberg/catalog/rest/__init__.py index 7955c3320f..dfe8af009a 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -427,9 +427,7 @@ def add_headers(self, request: PreparedRequest, **kwargs: Any) -> None: # pylin # For empty bodies, explicitly set the content hash header to the SHA256 of an empty string body = request.body if body in (None, b"", ""): - request.headers["x-amz-content-sha256"] = ( - "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" - ) + request.headers["x-amz-content-sha256"] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" aws_request = AWSRequest( method=request.method, url=url, params=params, data=request.body, headers=dict(request.headers)