Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

324
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda