gpt4 book ai didi

Python3 : Azure Key Vault Keys, 创建 RAS key :类型错误

转载 作者:行者123 更新时间:2023-12-03 04:07:22 34 4
gpt4 key购买 nike

以下示例:

https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/keyvault/azure-keyvault-keys

每当我运行以下代码时:

rsa_key = key_client.create_rsa_key("rsa-key-demo", size=2048)
print(rsa_key.name)
print(rsa_key.key_type)

key 将在我的 Azure keyVult 中创建,但是我总是收到以下错误:

Traceback (most recent call last): File "c:/Users/user/Desktop/azure_keyValut_demo.py", line 152, in rsa_key = key_client.create_rsa_key("rsa-key-demo", size=2048) File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\tracing\decorator.py", line 62, in wrapper_use_tracer return func(*args, **kwargs) # type: ignore File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\keyvault\keys_client.py", line 131, in create_rsa_key return self.create_key(name, key_type="RSA-HSM" if hsm else "RSA", **kwargs) File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\core\tracing\decorator.py", line 62, in wrapper_use_tracer return func(*args, **kwargs) # type: ignore File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\keyvault\keys_client.py", line 96, in create_key **kwargs File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\azure\keyvault\keys_shared_generated\v7_0\operations_key_vault_client_operations.py", line 96, in create_key deserialized = self._deserialize('KeyBundle', response) File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\msrest\serialization.py", line 1180, in call data = self._unpack_content(response_data, content_type) File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\site-packages\msrest\serialization.py", line 1334, in unpack_content return json.loads(data) File "C:\Users\user\AppData\Local\Programs\Python\Python36\lib\json_init.py", line 348, in loads 'not {!r}'.format(s.class.name)) TypeError: the JSON object must be str, bytes or bytearray, not 'method'


我不太明白为什么会抛出该异常。

我在 stackoverflow 上找到了这个,但仍然无法理解发生了什么:

Why won't python3 load this json string?


代码在Python2.7上运行成功,没有任何问题

所有关键操作(创建、删除、获取)都会抛出异常

所有加密操作也会发生这种情况

最佳答案

根据我的测试,如果我们在0.6.x版本下使用msrest,就会出现错误。我的测试步骤如下

我的requirements.txt

azure-common==1.1.23
azure-core==1.1.1
azure-identity==1.1.0
azure-keyvault-keys==4.0.0
certifi==2019.11.28
cffi==1.13.2
chardet==3.0.4
cryptography==2.8
idna==2.8
isodate==0.6.0
msal==1.0.0
msal-extensions==0.1.3
msrest==0.5.5
oauthlib==3.1.0
portalocker==1.5.2
pycparser==2.19
PyJWT==1.7.1
pywin32==227
requests==2.22.0
requests-oauthlib==1.3.0
six==1.13.0
urllib3==1.25.7

我的代码

from azure.identity import ClientSecretCredential
from azure.keyvault.keys import KeyClient

tenant_id=''
client_id=''
client_secret=''
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
client = KeyClient("https://testkey08.vault.azure.net/", credential)

key = client.create_rsa_key("rsa-key-demo", size=2048)
print(key.name)
print(key.key_type)

enter image description here

因此,请将 merest 更新为 0.6.x。详细步骤如下

  1. 创建项目
python -m venv mytestenv # Might be "python3" or "py -3.6" depending on your Python installation
cd mytestenv
source bin/activate # Linux shells (Bash, ZSH, etc.)
scripts\activate # Windows shells (PowerShell, CMD)
  • 安装 SDK我的requirements.txt
  • azure-common==1.1.23
    azure-core==1.1.1
    azure-identity==1.1.0
    azure-keyvault-keys==4.0.0
    certifi==2019.11.28
    cffi==1.13.2
    chardet==3.0.4
    cryptography==2.8
    idna==2.8
    isodate==0.6.0
    msal==1.0.0
    msal-extensions==0.1.3
    msrest==0.6.10
    oauthlib==3.1.0
    portalocker==1.5.2
    pycparser==2.19
    PyJWT==1.7.1
    pywin32==227
    requests==2.22.0
    requests-oauthlib==1.3.0
    six==1.13.0
    urllib3==1.25.7
    xlrd==1.2.0

    pip install -r requirements.txt
  • 代码
  • from azure.identity import ClientSecretCredential
    from azure.keyvault.keys import KeyClient

    tenant_id=''
    client_id=''
    client_secret=''
    credential = ClientSecretCredential(tenant_id, client_id, client_secret)
    client = KeyClient("https://testkey08.vault.azure.net/", credential)

    key = client.create_rsa_key("rsa-key-demo", size=2048)
    print(key.name)
    print(key.key_type)

    enter image description here

    关于Python3 : Azure Key Vault Keys, 创建 RAS key :类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59157372/

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