Report this

What is the reason for this report?

List objects in Spaces

Posted on February 18, 2025

I’m trying to list objects in my Spaces bucket:

session = boto3.session.Session()
s3_client = session.client('s3',
    region_name='blr1',
    endpoint_url=my_endpoint_url,
)
response = client.list_objects_v2(Bucket=my_spaces_name)

I keep getting the error: Error: An error occurred (NotImplemented) when calling the ListObjectsV2 operation: Server does not support one or more requested headers.

When I check the documentation it says v2 is supported. Even dropping the v2 doesn’t change the nature of the error. Any help welcome.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi,

It looks like you’re using client instead of s3_client when calling the list_objects_v2 method. Update your code to use the correct variable name:

session = boto3.session.Session()
s3_client = session.client('s3',
    region_name='blr1',
    endpoint_url=my_endpoint_url,
)

response = s3_client.list_objects_v2(Bucket=my_spaces_name)
print(response)

Also, make sure your endpoint_url is correctly set to something like https://blr1.digitaloceanspaces.com.

- Bobby

Heya,

something like the following should work for you

session = boto3.session.Session()
s3_client = session.client('s3',
    region_name='blr1',
    endpoint_url=my_endpoint_url,
)

response = s3_client.list_objects(Bucket=my_spaces_name)

if 'Contents' in response:
    for obj in response['Contents']:
        print(obj['Key'])
else:
    print("No objects found or listing is not supported")

As said you need to use s3_client.

Heya, @qumata

You can use s3cmd as an alternative to list objects in your Spaces bucket.

  1. Install s3cmd
sudo apt install s3cmd

Or via pip:

pip install s3cmd
  1. Configure s3cmd for DigitalOcean Spaces
s3cmd --configure

Set these values:

  • Access Key: Your Spaces access key
  • Secret Key: Your Spaces secret key
  • Default region: blr1
  • S3 Endpoint: https://blr1.digitaloceanspaces.com
  • Use HTTPS: Yes
  • Signature Version: s3v4
  1. List Objects in a Bucket
s3cmd ls s3://your-bucket-name/
  1. List Objects Recursively
s3cmd ls --recursive s3://your-bucket-name/

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.