Skip to content

Commit

Permalink
fix(region cache): x-amz-bucket-region can be missing for s3 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
shcheklein committed Jan 11, 2025
1 parent 51e3c80 commit bd5baca
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions s3fs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,21 @@ async def get_bucket_client(self, bucket_name=None):
try:
response = await general_client.head_bucket(Bucket=bucket_name)
except ClientError as e:
region = (
e.response["ResponseMetadata"]
.get("HTTPHeaders", {})
.get("x-amz-bucket-region")
logger.debug("RC: HEAD_BUCKET call for %r has failed", bucket_name)
response = e.response

region = (
response["ResponseMetadata"]
.get("HTTPHeaders", {})
.get("x-amz-bucket-region")
)

if not region:
logger.debug(
"RC: No region in HEAD_BUCKET call response for %r, returning the general client",
bucket_name,
)
if not region:
logger.debug(
"RC: HEAD_BUCKET call for %r has failed, returning the general client",
bucket_name,
)
return general_client
else:
region = response["ResponseMetadata"]["HTTPHeaders"]["x-amz-bucket-region"]
return general_client

if region not in self._regions:
logger.debug(
Expand Down

0 comments on commit bd5baca

Please sign in to comment.