Python Jwt 错误“找不到算法”和另一个错误“您是否安装了加密组件”

问题描述 投票:0回答:1

我正在使用 python jwt 使用算法 RS512 获取 jwt 令牌。 但我不断收到找不到算法的错误。 另外,我收到一条错误消息,指出未找到加密组件。不过我已经安装了 pycryptodome。

任何人都可以帮助解决上述问题吗?下面是我的代码:

def generate_jwt_token(self):
    privateKeyPath = './config/privateKey.pem'
    payload = {'name': 'abc'}
    with open(privateKeyPath ,'rb') as f:
        privateKey = f.read()
    jwtToken = jwt.encode(payload, key=privateKey, algorithm='RS512')
    print(jwtToken)
python-3.x api jwt pycrypto pycryptodome
1个回答
0
投票

得到了未找到算法的答案:- 不要安装 pycrypto 或 pycryptodome,而是将 crypto 组件与 jwt 一起安装。 pip install pyjwt[加密]

© www.soinside.com 2019 - 2024. All rights reserved.