Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

327
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda