From a8deac98a11e1b5aa155d4347c576470a459bd63 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 a28ff562bd..cfcad49cdf 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -434,7 +434,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 1ef9f2f9b926f46a44a5ede9a825222454bea66d 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 cfcad49cdf..7dd79a93f1 100644 --- a/pyiceberg/catalog/rest/__init__.py +++ b/pyiceberg/catalog/rest/__init__.py @@ -439,9 +439,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)