gpt4 book ai didi

Python 类自身值错误,预期类型 'str' 得到了 Tuple[str],天蓝色 ClientSecretCredential

转载 作者:行者123 更新时间:2023-12-05 00:55:28 28 4
gpt4 key购买 nike

我创建了一个类并试图将它的一个值分配给需要一个字符串的东西,但是它说它正在获取一个 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

逗号使变量成为元组

关于Python 类自身值错误,预期类型 'str' 得到了 Tuple[str],天蓝色 ClientSecretCredential,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64496264/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com