Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
listing the object of a bucket works through boto, but throws error through boto3

I want to list the objects of a bucket. I used the following code in boto and it worked fine

from boto.s3.connection import S3Connection
from boto.s3.connection import OrdinaryCallingFormat
from boto.s3.key import Key

destination = S3Connection(aws_access_key_id=aws_access_key_id, aws_secret_access_key='lokesh', is_secure=False, port=9090, host=host, calling_format=OrdinaryCallingFormat())
destination_bucket = destination.get_bucket(bucket_name)

destination_all_keys = destination_bucket.get_all_keys()
print destination_all_keys
for key in destination_all_keys:
    print key

However if I am using boto3, then I am getting error

botocore.exceptions.ClientError: An error occurred (MethodNotAllowed) when calling the ListObjects operation: The specified method is not allowed against this resource.

below is the boto3 code that gives error

import boto3
destination = boto3.client('s3',
                    endpoint_url=endpoint,
                    aws_access_key_id=aws_access_key_id,
                    aws_secret_access_key=aws_secret_access_key,
                    use_ssl=False,
                    config=timeout_config
                    )

destination.list_objects(Bucket=bucket_name)['Contents']
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The correct way to do this is in boto3 is using boto3 session .

import boto3
sess = boto3.session(
    endpoint_url=endpoint,
    aws_access_key_id=aws_access_key_id,
    aws_secret_access_key=aws_secret_access_key,
    use_ssl=False,
    config=timeout_config)

s3 = sess.client("s3")
s3.list_objects(Bucket=bucket_name)

In addition, passing API key is a bad design. If you deploy application into any AWS services that use IAM roles, the accesskey lines will give you headache.

Just setup your local .aws credential file and you can use simple setup such as this.

import boto3
sess = boto3.session(
        endpoint_url=endpoint,
        use_ssl=False,
        config=timeout_config)

    s3 = sess.client("s3")
    s3.list_objects(Bucket=bucket_name)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!