Question

List objects in Spaces

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.


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
February 19, 2025

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

KFSys
Site Moderator
Site Moderator badge
February 19, 2025

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.

alexdo
Site Moderator
Site Moderator badge
February 23, 2025

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!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.