Home > Net >  Unable to locate credentials in boto3 AWS
Unable to locate credentials in boto3 AWS

Time:04-04

I'm trying to view S3 bucket list through a python scripts using boto3. Credential file and config file is available in the C:\Users\user1.aws location. Secret access and access key available there for user "vscode". But unable to run the script which return exception message as "botocore.exceptions.NoCredentialsError: Unable to locate credentials".

Code sample follows, import boto3 s3 = boto3.resource('s3') for bucket in s3.buckets.all(): print(bucket.name)

Do I need to specify user mentioned above ("vscode") ?

Copied the credential and config file to folder of python script is running. But same exception occurs.

CodePudding user response:

When I got this error, I replaced resource with client and also added the secrets during initialization:

client = boto3.client('s3', region_name=settings.AWS_REGION, aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
                          aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY)

CodePudding user response:

You can try with boto3.client('s3') instead of boto3.resource('s3')

  • Related