Home > database >  expected str instance, set found when using Boto3
expected str instance, set found when using Boto3

Time:05-23

I'm using boto3 and putting in my credentials like-so:

dynamodb_client = boto3.client('dynamodb', region_name='us-west-2', aws_access_key_id={access_key}, aws_secret_access_key={secret_key})

I get this error and from searching online it seems it's because I don't have my session token included as well. Is there a better way to input my access keys and session token?

For context, I don't have this issue when running my program locally(since I'm logged in to my account through the aws cli). I'm creating a docker image and when I run the docker image that's where I got the authentication error, so I added my credentials and now I'm getting this error that I'm assuming is session key related. I'm curious if there's another way or if I have to create a temporary session token and add it to my environment variables folder as well

File "/usr/local/lib/python3.8/site-packages/botocore/auth.py", line 424, in _inject_signature_to_request
    auth_str = ['AWS4-HMAC-SHA256 Credential=%s' % self.scope(request)]
  File "/usr/local/lib/python3.8/site-packages/botocore/auth.py", line 373, in scope
    return '/'.join(scope)
TypeError: sequence item 0: expected str instance, set found

CodePudding user response:

The issue isn't that you don't have a session token.

The issue is that you're wrapping your access key ID & secret access key within dictionaries but Boto3 expects 2 string values.

The hint is in:

expected str instance, set found

Replace:

dynamodb_client = boto3.client(
  'dynamodb',
  region_name='us-west-2',
  aws_access_key_id={access_key},
  aws_secret_access_key={secret_key}
)

With:

dynamodb_client = boto3.client(
  'dynamodb',
  region_name='us-west-2',
  aws_access_key_id=access_key,
  aws_secret_access_key=secret_key
)

Note the lack of curly braces which will create & initialise a dictionary for you.

  • Related