首页 > 解决方案 > Python 3.7 Authlib UnsupportedAlgorithmError

问题描述

我在 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

为什么会出现这个错误?我能做些什么来修复它?

标签: pythonauthlib

解决方案


密码学没有manylinux适用于 CPython 3.7 的轮子。在这种情况下,您需要自己在 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


推荐阅读