Python 类自值错误,预期类型“str”得到了 Tuple[str],而 azure ClientSecretCredential

Ari*_*Ari 1 python azure-sdk

我创建了一个类并试图将它的一个值分配给需要字符串的东西,但是它说它得到了一个Tuple[str],但我不知道怎么做?

from azure.identity import ClientSecretCredential


class ServicePrincipal:
    """
    Service Principal class is used to authorise the service
    """
    def __init__(self):
        self.tenant_id = "123-xyz",
        self.client_id = "123-abc",
        self.client_secret = "123-lmn",

    def credentials(self):
        """
        Returns a ClientServiceCredential object using service principal details
        :return:
        """
        # ISSUE IS HERE 
        return ClientSecretCredential(
            tenant_id=self.tenant_id, # <---- Getting Tuple[str]
            client_id=self.client_id, # <---- Getting Tuple[str]
            client_secret=self.client_secret, # <---- Getting Tuple[str]
        )
Run Code Online (Sandbox Code Playgroud)

如果我将字符串直接复制粘贴到参数中就好了。所以这self.value以某种方式引起了问题?

Val*_*eti 5

您应该删除此处的逗号:

def __init__(self):
        self.tenant_id = "123-xyz",  # remove the comma
        self.client_id = "123-abc",  # remove the comma
        self.client_secret = "123-lmn",  # remove the comma
Run Code Online (Sandbox Code Playgroud)

逗号使变量成为元组