Skip to content

Commit

Permalink
handle redirects in HeadBucket (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Dec 29, 2022
1 parent 5917684 commit f57f9d8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions s3fs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ async def get_bucket_client(self, bucket_name=None):

try:
response = await general_client.head_bucket(Bucket=bucket_name)
except ClientError:
logger.debug(
"RC: HEAD_BUCKET call for %r has failed, returning the general client",
bucket_name,
except ClientError as e:
region = (
e.response["ResponseMetadata"]
.get("HTTPHeaders", {})
.get("x-amz-bucket-region")
)
return general_client
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"]

Expand Down

0 comments on commit f57f9d8

Please sign in to comment.