An error occurred (403) when calling the HeadObject operation: Forbidden
Posted: Wed Jun 28, 2023 1:10 am America/New_York
import boto3
import requests
user = 'someusername'
password = 'somepassword
url = 'https://archive.podaac.earthdata.nasa.gov/s3credentials'
url = requests.get(url, allow_redirects=False).headers['Location']
creds = requests.get(url, auth=(user, password)).json()
# creds returned containing sessionToken, secretAcccessKey and accessKeyId
aws_access_key_id = creds['accessKeyId']
aws_secret_access_key = creds['secretAccessKey']
aws_session_token = creds['sessionToken']
region = 'us-west-2'
# pass the retrieve session details to boto3 session
session = boto3.Session(aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token,
region_name=region
)
client = session.client('s3', verify=False)
bucket = 'podaac-ops-cumulus-protected'
prefix = ''
delimiter = '/'
key = "OSTIA-UKMO-L4-GLOB-v2.0/20230626120000-UKMO-L4_GHRSST-SSTfnd-OSTIA-GLOB-v02.0-fv02.0.nc"
filename = '2023062612-GHRSST-OSTIA.nc'
print('downloading file starting....')
client.download_file(Bucket=bucket, Key=key, Filename=filename)
print('downloading file complete....')
This code executes up until the client download_file line which throws
Traceback (most recent call last):
File "test.py", line 46, in <module>
client.download_file(Bucket=bucket, Key=key, Filename=filename)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
I have checked my aws region that the code is running in and is set to us-west-1.
I have seen other questions around this same issue but with no resolution to how to direct download the data from s3 bucket. All the threads i have seen around the place talk about a misconfigured s3 bucket.
import requests
user = 'someusername'
password = 'somepassword
url = 'https://archive.podaac.earthdata.nasa.gov/s3credentials'
url = requests.get(url, allow_redirects=False).headers['Location']
creds = requests.get(url, auth=(user, password)).json()
# creds returned containing sessionToken, secretAcccessKey and accessKeyId
aws_access_key_id = creds['accessKeyId']
aws_secret_access_key = creds['secretAccessKey']
aws_session_token = creds['sessionToken']
region = 'us-west-2'
# pass the retrieve session details to boto3 session
session = boto3.Session(aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_session_token,
region_name=region
)
client = session.client('s3', verify=False)
bucket = 'podaac-ops-cumulus-protected'
prefix = ''
delimiter = '/'
key = "OSTIA-UKMO-L4-GLOB-v2.0/20230626120000-UKMO-L4_GHRSST-SSTfnd-OSTIA-GLOB-v02.0-fv02.0.nc"
filename = '2023062612-GHRSST-OSTIA.nc'
print('downloading file starting....')
client.download_file(Bucket=bucket, Key=key, Filename=filename)
print('downloading file complete....')
This code executes up until the client download_file line which throws
Traceback (most recent call last):
File "test.py", line 46, in <module>
client.download_file(Bucket=bucket, Key=key, Filename=filename)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
I have checked my aws region that the code is running in and is set to us-west-1.
I have seen other questions around this same issue but with no resolution to how to direct download the data from s3 bucket. All the threads i have seen around the place talk about a misconfigured s3 bucket.