gpt4 book ai didi

python - 类型错误 : string indices must be integers - while trying to read secret

转载 作者:行者123 更新时间:2023-12-03 06:51:56 25 4
gpt4 key购买 nike

我尝试读取 Azure key 保管库中的 secret 值。为了实现这个目标,我尝试了 here 中的代码:

from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient

# Create a SecretClient using default Azure credentials
credential = DefaultAzureCredential()
secret_client = SecretClient(vault_url, credential)
secret = secret_client.get_secret(secret_name)
print(secret.value)

但运行后我收到此错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\tefadm\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\core\paging.py", line 128, in __next__
return next(self._page_iterator)
File "C:\Users\tefadm\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\core\paging.py", line 76, in __next__
self._response = self._get_next(self.continuation_token)
File "C:\Users\tefadm\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\keyvault\secrets\_generated\v7_3\operations\_key_vault_client_operations.py", line 798, in get_next
map_error(status_code=response.status_code, response=response, error_map=error_map)
File "C:\Users\tefadm\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\core\exceptions.py", line 106, in map_error
error = error_type(response=response)
File "C:\Users\tefadm\AppData\Local\Programs\Python\Python310\lib\site-packages\azure\keyvault\secrets\_shared\exceptions.py", line 24, in _get_exception_for_key_vault_error
message = "({}) {}".format(body["error"]["code"], body["error"]["message"]) # type: Optional[str]
TypeError: string indices must be integers

您知道如何解决这个问题吗?

最佳答案

我在我的环境中进行了尝试,并通过相同的代码成功检索了 secret 。

from  azure.keyvault.secrets  import  SecretClient
from azure.identity import DefaultAzureCredential
keyVaultName = ["<vault name>"]
KVUri = f"https://{Vault name}.vault.azure.net"
credential = DefaultAzureCredential()
secret_client = SecretClient(vault_url=KVUri, credential=credential)
secret= secret_client.get_secret("secret2")#secretname
print(secret.value)

在我的 keystore 中,我有一个 secret ,请参阅下面的快照:

enter image description here

python TypeError: string indices must be integers

上述错误可能会导致您是否传递了 keyvault 名称而不是 secret 名称。

现在我尝试了您的代码并获得了成功的输出,它已从 keyvault 检索了 secret 。

enter image description here

关于python - 类型错误 : string indices must be integers - while trying to read secret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73530883/

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