Skip to main content
 首页 » 编程设计

Python 3.7 Authlib UnsupportedAlgorithmError

2024年12月31日24kuangbin

我在 Docker 中的 Ubuntu 18.04 上遇到了这个问题。当我在 macOS 上开发这个应用程序时,没有这样的错误。

我用这个 Dockerfile 构建镜像:https://pastebin.com/rG32a0dv

要求.txt:

Flask==1.0.2 
uWSGI==2.0.17.1 
Authlib==0.10 
cryptography==2.3.1 

代码中的用法:

header = {'alg': 'RS256'} 
payload = {'login': login} 
 
auth_token = jwt.encode(header, payload, private_key) 

和

try: 
    claims = jwt.decode(auth_token, public_key) 
except BadSignatureError: 
    return False 

整个 Flask 应用:https://pastebin.com/9vVJQL1w

我有错误:

authlib.specs.rfc7515.errors.UnsupportedAlgorithmError: unsupported_algorithm: 

详情:https://pastebin.com/MjFRce1F

为什么会出现这个错误?我该怎么做才能修复它?

请您参考如下方法:

密码学没有用于 CPython 3.7 的 manylinux 轮子。在这种情况下,您需要自己在 linux 上构建密码学。遵循文档:

https://cryptography.io/en/latest/installation/#building-cryptography-on-linux

您可以尝试导入一些密码学模块来验证:

from cryptography.hazmat.primitives import hashes 
from cryptography.hazmat.primitives.asymmetric.utils import ( 
    decode_dss_signature, encode_dss_signature 
) 
from cryptography.hazmat.primitives.asymmetric.ec import ECDSA 
from cryptography.hazmat.primitives.asymmetric import padding 

通过https://github.com/lepture/authlib/blob/v0.10/authlib/specs/rfc7518/_backends/_jws_cryptography.py