Todos os produtos
Search
Central de documentação

Object Storage Service:Excluir tags de objeto (OSS SDK for Python 1.0)

Última atualização: Jul 03, 2026

Exclua tags desnecessárias de um objeto conforme necessário. Se o versionamento estiver ativado no bucket que armazena o objeto, o Object Storage Service (OSS) exclui as tags da versão atual por padrão. Para excluir as tags de uma versão específica, especifique o ID da versão do objeto.

Observações

  • Este tópico usa o endpoint público da região China (Hangzhou). Para acessar o OSS a partir de outros serviços da Alibaba Cloud na mesma região, use um endpoint interno. Para obter mais informações sobre regiões e endpoints do OSS, consulte Regiões e endpoints.

  • Este tópico demonstra como criar uma instância OSSClient com um endpoint do OSS. Para configurações alternativas, como uso de domínio personalizado ou autenticação com credenciais do Security Token Service (STS), consulte Inicialização.

  • Para excluir as tags de um objeto, você deve ter a permissão oss:DeleteObjectTagging. Para obter mais informações, consulte Conceder uma política personalizada.

Excluir as tags de um objeto

Se o versionamento não estiver ativado no bucket que armazena o objeto, exclua as tags conforme necessário. Se o versionamento estiver ativado, o OSS exclui as tags da versão atual do objeto por padrão.

O código a seguir mostra como excluir as tags do objeto exampleobject.txt no diretório exampledir do bucket examplebucket:

# -*- coding: utf-8 -*-

import oss2
from oss2.models import Tagging, TaggingRule
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. 
object_name = 'exampledir/exampleobject.txt'

# Delete the tags of the object. 
result = bucket.delete_object_tagging(object_name)
print('http response status: ', result.status)

Excluir as tags de uma versão específica de um objeto

Se o versionamento estiver ativado no bucket que armazena o objeto, exclua as tags de uma versão específica ao especificar o ID da versão do objeto.

O código a seguir mostra como excluir as tags de uma versão específica do objeto exampleobject.txt no diretório exampledir do bucket examplebucket:

Nota

Para obter mais informações sobre como obter IDs de versão, consulte Listar objetos (OSS SDK for Python 1.0).

# -*- coding: utf-8 -*-

import oss2
from oss2.models import Tagging
from oss2.credentials import EnvironmentVariableCredentialsProvider

# Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured. 
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())

# Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. 
endpoint = "https://oss-cn-hangzhou.aliyuncs.com"
# Specify the ID of the region that maps to the endpoint. Example: cn-hangzhou. This parameter is required if you use the signature algorithm V4.
region = "cn-hangzhou"

# Specify the name of the bucket.
bucket = oss2.Bucket(auth, endpoint, "examplebucket", region=region)

# Specify the full path of the object. Do not include the bucket name in the full path. Example: exampledir/exampleobject.txt. 
object_name = 'exampledir/exampleobject.txt'
# Specify the version ID of the object. 
version_id = 'CAEQMxiBgICAof2D0BYiIDJhMGE3N2M1YTI1NDQzOGY5NTkyNTI3MGYyMzJm****'

params = dict()
params['versionId'] = version_id
bucket.delete_object_tagging(object_name, params=params)

Referências