diff --git a/pyiceberg/io/fsspec.py b/pyiceberg/io/fsspec.py index af643c8d46..ff8286c92f 100644 --- a/pyiceberg/io/fsspec.py +++ b/pyiceberg/io/fsspec.py @@ -23,6 +23,7 @@ from copy import copy from functools import lru_cache, partial from typing import ( + TYPE_CHECKING, Any, Callable, Dict, @@ -31,8 +32,6 @@ from urllib.parse import urlparse import requests -from botocore import UNSIGNED -from botocore.awsrequest import AWSRequest from fsspec import AbstractFileSystem from fsspec.implementations.local import LocalFileSystem from requests import HTTPError @@ -83,8 +82,11 @@ logger = logging.getLogger(__name__) +if TYPE_CHECKING: + from botocore.awsrequest import AWSRequest -def s3v4_rest_signer(properties: Properties, request: AWSRequest, **_: Any) -> AWSRequest: + +def s3v4_rest_signer(properties: Properties, request: "AWSRequest", **_: Any) -> "AWSRequest": signer_url = properties.get(S3_SIGNER_URI, properties["uri"]).rstrip("/") signer_endpoint = properties.get(S3_SIGNER_ENDPOINT, S3_SIGNER_ENDPOINT_DEFAULT) @@ -114,7 +116,7 @@ def s3v4_rest_signer(properties: Properties, request: AWSRequest, **_: Any) -> A return request -SIGNERS: Dict[str, Callable[[Properties, AWSRequest], AWSRequest]] = {"S3V4RestSigner": s3v4_rest_signer} +SIGNERS: Dict[str, Callable[[Properties, "AWSRequest"], "AWSRequest"]] = {"S3V4RestSigner": s3v4_rest_signer} def _file(_: Properties) -> LocalFileSystem: @@ -141,6 +143,8 @@ def _s3(properties: Properties) -> AbstractFileSystem: register_events["before-sign.s3"] = signer_func_with_properties # Disable the AWS Signer + from botocore import UNSIGNED + config_kwargs["signature_version"] = UNSIGNED else: raise ValueError(f"Signer not available: {signer}")