Python class 自值错误,预期类型 'str' 得到的是 Tuple[str],azure ClientSecretCredential

Python class self value error, Expected type 'str' got Tuple[str] instead, azure ClientSecretCredential

我创建了一个 class 并试图将它的一个值分配给需要字符串的东西,但是它说它得到的是 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]
        )

如果我将字符串直接复制粘贴到参数中就可以了。所以 self.value 不知何故引起了问题?

您应该删除此处的逗号:

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

逗号使变量成为元组