MattB
MattB

Reputation: 155

Connect to S3 compatible storage with boto3

I'm struggling to get boto3 to connect to an S3 compatible resource, I can't seem to find a decent example of this on the boto3 pages so my attempt is below (taken from https://docs.oracle.com/cd/E91275_01/html/E96223/gsyqi.html)

I get the Traceback (full output below) AttributeError: 'str' object has no attribute 'get'

import logging
import boto3
from mycreds.creds import Mycreds

# Pull in my config
access_key = Mycreds.access_key
secret_key = Mycreds.secret_key
endpoint = Mycreds.endpoint

b3_session = boto3.Session(aws_access_key_id=access_key,
                           aws_secret_access_key=secret_key,
                           region_name='us-east-1')

b3_client = b3_session.client('s3', endpoint_url=endpoint)

bucket = b3_client.create_bucket(Bucket='somenewbucket')

Traceback:

Traceback (most recent call last):
  File "/home/mattb/Documents/code/play_area/boto3_s3test/s3_test.py", line 14, in <module>
    b3_client = b3_session.client('s3', endpoint_url=endpoint)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/boto3/session.py", line 263, in client
    aws_session_token=aws_session_token, config=config)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/session.py", line 835, in create_client
    client_config=config, api_version=api_version)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/client.py", line 85, in create_client
    verify, credentials, scoped_config, client_config, endpoint_bridge)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/client.py", line 287, in _get_client_args
    verify, credentials, scoped_config, client_config, endpoint_bridge)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/args.py", line 73, in get_client_args
    endpoint_url, is_secure, scoped_config)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/args.py", line 153, in compute_client_args
    s3_config=s3_config,
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/args.py", line 215, in _compute_endpoint_config
    s3_config=s3_config, **resolve_endpoint_kwargs)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/args.py", line 228, in _compute_s3_endpoint_config
    endpoint_config, resolve_endpoint_kwargs['endpoint_bridge'])
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/args.py", line 261, in _set_region_if_custom_s3_endpoint
    endpoint = endpoint_bridge.resolve('s3')
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/client.py", line 364, in resolve
    resolved, service_name, region_name, endpoint_url, is_secure)
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/client.py", line 382, in _create_endpoint
    if self._is_s3_dualstack_mode(service_name):
  File "/home/mattb/.local/share/virtualenvs/boto3_s3test-aHfp37jc/lib/python3.7/site-packages/botocore/client.py", line 414, in _is_s3_dualstack_mode
    enabled = self.scoped_config.get('s3', {}).get(
AttributeError: 'str' object has no attribute 'get'

Upvotes: 3

Views: 3605

Answers (2)

Sapience
Sapience

Reputation: 1638

I got the same issue, thanks to the tip from @MattB, I found the root cause is in ~/.aws/config. I need to add a tab in the front of the third line below. The indentation was accidentally remove earlier.

[default]
s3=
    signature_version=s3v4
region=us-east-1

Upvotes: 1

MattB
MattB

Reputation: 155

Just in case anyone else comes across the same problem, I eventually tracked it down to a ~/.aws/config file which, once I'd removed it fixed the issue.

Unfortunately I should have moved rather than delete the file so I couldn't diagnose it further.

Upvotes: 0

Related Questions