Skip to content

Commit

Permalink
Fix 403 forbidden error exeception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkjin99 committed Feb 28, 2024
1 parent 0b2c123 commit 434e92d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/obs3dian/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
bucket_name: str,
aws_access_key: str,
aws_secret_key: str,
useprofile: bool = True,
useprofile: bool,
) -> None:

if useprofile:
Expand All @@ -30,6 +30,7 @@ def __init__(
self.session = boto3.Session(
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
region_name="ap-northeast-2",
)
else:
raise ValueError("AWS key is required")
Expand All @@ -45,9 +46,12 @@ def _check_bucket_exist(self) -> bool:

except ClientError as e:
error_code = e.response["Error"]["Code"]
if error_code != "404": # if no permission or bad request raise error
if error_code == "404": # if no bukcet return false
return False
elif error_code == "403": # 403 means bucket exists but no permission
return True
else:
raise e
return False # 404 is not exists error

def _put_public_access_policy(self) -> None:
policy = {
Expand Down

0 comments on commit 434e92d

Please sign in to comment.