Todos os produtos
Search
Central de documentação

Object Storage Service:Exclua tags de objetos usando o OSS SDK for Python 2.0

Última atualização: Sep 25, 2026

Este tópico descreve como usar o OSS SDK for Python 2.0 para excluir as tags de um objeto.

Observações

  • O código de exemplo deste tópico usa o ID da região cn-hangzhou, na região China (Hangzhou). Por padrão, use um endpoint público para acessar recursos em um bucket. Para acessar os recursos do bucket a partir de outros serviços da Alibaba Cloud na mesma região do bucket, use um endpoint interno. Para mais informações sobre as regiões e endpoints do OSS, consulte Regions and endpoints.

  • Um par chave-valor identifica objetos. Para mais informações sobre tags de objetos, consulte Tag objects no Guia do Desenvolvedor do OSS.

  • Para mais informações sobre como excluir as tags de um objeto, consulte DeleteObjectTagging.

  • Para excluir as tags de um objeto, é necessário ter a permissão oss:DeleteObjectTagging. Para mais informações, consulte Grant a custom policy.

Método

delete_object_tagging(request: DeleteObjectTaggingRequest, **kwargs) → DeleteObjectTaggingResult

Parâmetros da requisição

Parâmetro

Tipo

Descrição

request

DeleteObjectTaggingRequest

Os parâmetros da requisição. Para mais informações, consulte DeleteObjectTaggingRequest

Parâmetros de resposta

Tipo

Descrição

DeleteObjectTaggingResult

O valor de retorno. Para mais informações, consulte DeleteObjectTaggingResult

Para a definição completa do método, consulte delete_object_tagging.

Código de exemplo

O código de exemplo a seguir exclui as tags de um objeto específico em um bucket:

import argparse
import alibabacloud_oss_v2 as oss

# Create a command-line parameter parser and define the parameters.
parser = argparse.ArgumentParser(description="delete object tagging sample")
# Add command-line arguments.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--key', help='The name of the object.', required=True)

def main():
    # Parse the command-line argument.
    args = parser.parse_args()

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

    # Use the default configuration to create a configuration object.
    cfg = oss.config.load_default()

    # Set the credential provider.
    cfg.credentials_provider = credentials_provider

    # Set the region.
    cfg.region = args.region

    # If an endpoint is provided, configure the endpoint.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Create an OSS client instance using the preceding configurations.
    client = oss.Client(cfg)

    # Delete the tags of the specified object.
    result = client.delete_object_tagging(oss.DeleteObjectTaggingRequest(
        bucket=args.bucket,
        key=args.key,
    ))

    # Print the result.
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          f' version id: {result.version_id},'
    )

# all the main function when the script is directly run.
if __name__ == "__main__":
    main()

Referência