You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用runserver_plus指定证书文件时遇lib模块属性缺失错误

解决AttributeError: module 'lib' has no attribute 'OpenSSL_add_all_algorithms'问题

核心原因

这个错误是pyOpenSSL与cryptography版本不兼容导致的。新版本的cryptography移除了OpenSSL_add_all_algorithms这个API,而旧版pyOpenSSL仍在调用该接口;反之,pyOpenSSL版本过旧也可能无法适配新版cryptography的内部结构。

解决方案

1. 安装兼容的版本组合

卸载现有pyOpenSSL和cryptography,重新安装经过验证的兼容版本:

pip uninstall -y pyopenssl cryptography
pip install pyopenssl==23.2.0 cryptography==41.0.7

注:若上述组合仍有问题,可尝试pyOpenSSL 22.x系列搭配cryptography 39.x系列。

2. 更新django-extensions

确保django-extensions是最新稳定版,避免旧版runserver_plus代码的调用逻辑问题:

pip install --upgrade django-extensions

3. 验证证书文件合法性

确认cert.crt是有效的SSL证书,可通过以下命令检查:

openssl x509 -in cert.crt -text -noout

证书损坏或格式错误也可能触发间接的依赖调用异常。

4. 临时替代方案(版本调整无效时)

如果以上方法均不生效,可让runserver_plus自动生成自签名证书:

runserver_plus --cert localhost

该命令会自动在当前目录生成localhost.crt和localhost.key,无需手动指定证书文件,同样能实现HTTPS启动。

内容的提问来源于stack exchange,提问作者s-kvng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 23:15:26