在 requests_http_signature 库中给出意外参数的算法

algorithm giving an unexpected argument in requests_http_signature library

在下面的代码中,我尝试使用 'RSA_V1_5_SHA256' 算法来创建连接到 API 的签名。然而,尽管文档以这种方式编写,但它似乎并未将算法识别为有效参数。

这里还有链接的文档, https://pyauth.github.io/requests-http-signature/#asymmetric-key-algorithms

auth = HTTPSignatureAuth(
    algorithm=algorithms.RSA_V1_5_SHA256, key=preshared_secret, key_id=signature_key_id
)

这是返回的特定错误, TypeError: __init__() got an unexpected keyword argument 'algorithm'.

我假设文档可能已经过时,因为我需要传递创建 public 和私钥时使用的密码,以正确验证我对 API 的请求。 .. 根据我在该库的源代码中看到的内容,passphrase/password 在其他可用算法中不是可接受的参数。

感谢任何帮助!

你完全正确,文档没有更新,通过检查 source code we can see that the __init__ method for the HTTPSignatureAuth class has no algorithm argument. Instead we find a signature_algorithm parameter (also we can see that this is the parameter that we need - source) 所以我会同意:

auth = HTTPSignatureAuth(
    signature_algorithm=algorithms.RSA_V1_5_SHA256, key=preshared_secret, key_id=signature_key_id
)

更改是在版本 v0.3.0 中进行的,因此如果您使用以前的版本,您将能够使用 algorithm 作为参数。但我会选择第一种方法。 (请注意,版本 v0.3.0 是 23 天前发布的,所以它是最新的,他们可能会很快更新文档!