Todos os produtos
Search
Central de documentação

Object Storage Service:Query bucket info using OSS SDK for Python 2.0

Última atualização: Jul 03, 2026

Use o OSS SDK for Python para consultar propriedades do bucket, como status de rastreamento de acesso, região, data de criação, ACL, proprietário, classe de armazenamento, tipo de redundância, endpoints, status de CRR, status de versionamento e método de criptografia.

Observações

  • O código de exemplo usa o ID da região cn-hangzhou (China (Hangzhou)) e o endpoint público. Para acessar o bucket a partir de serviços da Alibaba Cloud na mesma região, use o endpoint interno. Consulte Regiões e endpoints do OSS.

  • As credenciais de acesso são carregadas de variáveis de ambiente. Para mais detalhes sobre como configurar as credenciais de acesso, consulte Configurar credenciais de acesso.

  • A permissão oss:GetBucketInfo é necessária para consultar informações de um bucket. Para mais informações, consulte Conceder uma política personalizada.

Método

get_bucket_info(request: GetBucketInfoRequest, **kwargs) → GetBucketInfoResult

Parâmetros da solicitação

Parâmetro

Tipo

Descrição

request

GetBucketInfoRequest

Parâmetros da solicitação. GetBucketInfoRequest.

Parâmetros de resposta

Tipo

Descrição

GetBucketInfoResult

Corpo da resposta. GetBucketInfoResult.

Definição completa do método: get_bucket_info.

Código de exemplo

O exemplo a seguir consulta as informações de um bucket.

import argparse
import alibabacloud_oss_v2 as oss

# Create a command line parameter parser and describe the purpose of the script. This example describes how to query bucket info.
parser = argparse.ArgumentParser(description="Get detailed information about a specified OSS bucket.")

# Specify the required command line parameter --region, which specifies the region in which the bucket is located.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)

# Specify the required command line parameter --bucket, which specifies the name of the bucket. 
parser.add_argument('--bucket', help='The name of the bucket to get information for.', required=True)

# Specify the optional command line parameter --endpoint, which specifies the endpoint that other services can use to access OSS.
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS.')

def main():
    """
    The main function used to parse command line parameters and query detailed information about the specified bucket.
    """

    args = parser.parse_args()  # Parse command line parameters.

    # Load access credentials from environment variables for authentication.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Use the default configurations of the SDK and specify the credential provider and region.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider
    cfg.region = args.region

    # If the endpoint parameter is provided, assign this endpoint to the configuration settings.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Create an OSS client using the configured information.
    client = oss.Client(cfg)

    # Construct a request to query detailed information about the specified bucket.
    request = oss.GetBucketInfoRequest(bucket=args.bucket)

    # Send the request and retrieve the response.
    result = client.get_bucket_info(request)

    # Display various components in the response.
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          f' name: {result.bucket_info.name},'
          f' access monitor: {result.bucket_info.access_monitor},'
          f' location: {result.bucket_info.location},'
          f' creation date: {result.bucket_info.creation_date},'
          f' extranet endpoint: {result.bucket_info.extranet_endpoint},'
          f' intranet endpoint: {result.bucket_info.intranet_endpoint},'
          f' acl: {result.bucket_info.acl},'
          f' data redundancy type: {result.bucket_info.data_redundancy_type},'
          f' owner id: {result.bucket_info.owner.id},'
          f' owner display name: {result.bucket_info.owner.display_name},'
          f' storage class: {result.bucket_info.storage_class},'
          f' resource group id: {result.bucket_info.resource_group_id},'
    )

if __name__ == "__main__":
    main()  # Entry point of the script. The main function is invoked when the file is run directly.

Parâmetros comuns em solicitações de consulta

Parâmetro

Descrição

BucketInfo.Name

Nome do bucket.

BucketInfo.AccessMonitor

Status de rastreamento de acesso do bucket.

BucketInfo.Location

Região onde o bucket está localizado.

BucketInfo.CreationDate

Data de criação do bucket.

BucketInfo.ExtranetEndpoint

Endpoint público do bucket.

BucketInfo.IntranetEndpoint

Endpoint interno para acesso a partir de instâncias ECS na mesma região.

BucketInfo.ACL

ACL do bucket.

BucketInfo.RedundancyType

Tipo de redundância do bucket.

BucketInfo.Owner

Inclui:

  • BucketInfo.Owner.ID: ID do proprietário do bucket.

  • BucketInfo.Owner.DisplayName: nome do proprietário do bucket.

BucketInfo.StorageClass

Classe de armazenamento do bucket.

BucketInfo.SseRule

Inclui:

  • BucketInfo.SseRule.KMSDataEncryption: indica se o Key Management Service (KMS) criptografa dados no bucket.

  • BucketInfo.SseRule.KMSMasterKeyID: ID da chave mestra do cliente (CMK) usada para criptografia KMS.

  • BucketInfo.SseRule.SSEAlgorithm: método de criptografia do lado do servidor usado por padrão.

BucketInfo.Versioning

Status de versionamento do bucket.

BucketInfo.CrossRegionReplication

Status de replicação entre regiões (CRR) do bucket.

Referências