SSL错误不安全的遗产重新谈判禁用
我正在运行一个Python代码,其中我必须从 httpsconnectionpool(host ='ssd.jpl.nasa.gov',port = 443)
获得一些数据。但是,每次我尝试运行代码时,我都会收到以下错误。我在Mac OS 12.1上,
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='ssd.jpl.nasa.gov', port=443): Max retries exceeded with url: /api/horizons.api?format=text&EPHEM_TYPE=OBSERVER&QUANTITIES_[...]_ (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:997)')))
我真的不知道如何绕过这个问题。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
WARNING: When enabling Legacy Unsafe Renegotiation, SSL connections will be vulnerable to the Man-in-the-Middle prefix attack as described in
bugs/1963834“ rel =“ noreferrer”> https://bugs.launchpad.net/bugs/1963834
and httpps://bugs.launchpad.net/bugs.net/bugs.net/bunbuntu/+subuntu/gnutlsource/gnutlsource/gnutlsource/gnutls28 /+bug/1856428
请注意编辑系统的openssl.conf,因为一旦更新OpenSSL,您可能会丢失更改。
在任何目录中使用这些内容创建一个自定义
openssl.cnf
文件:运行程序之前,请确保您的
openssl_conf
环境变量设置为您的自定义openssl.cnf
在运行刮板时的完整路径:或类似:
或者,如果您使用的是Pipenv或Systemd或Docker,请将其放入您的
.env
文件中WARNING: When enabling Legacy Unsafe Renegotiation, SSL connections will be vulnerable to the Man-in-the-Middle prefix attack as described in CVE-2009-3555.
With the help of https://bugs.launchpad.net/bugs/1963834
and https://bugs.launchpad.net/ubuntu/+source/gnutls28/+bug/1856428
Beware that editing your system's openssl.conf is not recommended, because you might lose your changes once openssl is updated.
Create a custom
openssl.cnf
file in any directory with these contents:Before running your program, make sure your
OPENSSL_CONF
environment variable is set to your customopenssl.cnf
full path when running the scraper like so:or like so:
or, if you are using pipenv or systemd or docker, place this into your
.env
file的完整代码段
Harry Mallon 称呼:
Complete code snippets for Harry Mallon's answer:
Define a method for reuse:
Then use it in place of the requests call:
我在Linux上达到了相同的错误(当服务器不支持“ RFC 5746安全重新谈判”时发生,并且客户端使用OpenSSL 3(默认情况下执行该标准)。
这是一个解决方案(您可能必须稍微调整它)。
ssl
和urllib3
在Python代码中ssl
上下文op_legacy_server_connect
,并将其与您的自定义适配器一起使用。ssl.op_legacy_server_connect
在python中尚无()。但是,事实证明,在openssl中,其值为比特菲尔德(Bitfield)中的0x4。因此,我们可以做以下操作。I hit the same error on Linux (it happens when the server doesn't support "RFC 5746 secure renegotiation" and the client is using OpenSSL 3, which enforces that standard by default).
Here is a solution (you may have to adjust it slightly).
ssl
andurllib3
in your Python codessl
Context
ssl
context which enablesOP_LEGACY_SERVER_CONNECT
, and use it with your custom adapter.ssl.OP_LEGACY_SERVER_CONNECT
is not available in Python yet (https://bugs.python.org/issue44888). However it turns out that in OpenSSL its value is 0x4 in the bitfield. So we can do the following.当使用OpenSSL 3将不支持它的服务器连接到服务器时,此错误会出现。解决方案是在Python中降级加密软件包:
Run
PIP INSTALS gryptography == 36.0.2
在使用的环境中。来源: https://github.com/scrapy/scrapy/scrapy/scrapy/scrapy/issues/issues/5491
编辑:请参阅Harry Mallon和Ahmkara的答案以进行修复,而无需降级密码学
This error comes up when using OpenSSL 3 to connect to a server which does not support it. The solution is to downgrade the cryptography package in python:
run
pip install cryptography==36.0.2
in the used enviroment.source: https://github.com/scrapy/scrapy/issues/5491
EDIT: Refer to Harry Mallon and ahmkara's answer for a fix without downgrading cryptography
如果您想使用urlopen,该片段对我有用。
If you want to use urlopen, this snippet worked for me.
这并没有真正回答这个问题,但是同事从节点18转换为16,并停止遇到此错误。
This doesn't really answer the issue, but a coworker switched from Node 18 to 16 and stopped getting this error.
要解决Ruby中的相同问题,您可以在下面执行:
To fix the same problem in ruby you can do below:
如果您使用的是
conda
,通常Conda在每个环境中安装一个新的OpenSSL可执行文件。一个简单的修复方法是通过在环境中运行以下内容,将OpenSL降级到1.0。或查找针对特定Conda环境的OpenSL配置的位置,并遵循Jack Lee的答案。
您必须密切监视此网站的SSL版本,以确保您指定正确的频道。 https://anaconda.org/conda.org/conda-forge/conda-forge/openssl/labels
If you are using
conda
, usually conda installs a new openssl executable with each environment. One easy fix is to downgrade your openssl to 1.0 by running the following with your environment.Or find where the openssl config is for your specific conda environment and follow Jack Lee's answer.
You'll have to closely monitor the SSL versions from this website to ensure you specify the correct channel. https://anaconda.org/conda-forge/openssl/labels
该线程上有很多答案。他们都没有完全满足我的需求,所以我认为我也会为自己的解决方案做出贡献。希望其他人发现它很有价值。
我的设置
我在Ubuntu上运行Python 3.10 22.04.2。我正在使用
aiohttp
对HTTP请求不同步。我正在对内部LAN上的硬件提出HTTP请求,并且无法更新此硬件,以简单地停止使用不安全的SSL更新。
我的方法
我创建了一个自定义SSL上下文,然后通过SSL OP标志的SSL_OP_ALLO_ALLOD_UNSAFE_LEGACY_RENEGOTIATION'传递。我从这里得到了这个标志: ssl op flags
SSL验证(例如,在开发测试的情况下),您可以将以下两行添加到custom_ssl_context:
There are quite a few answers on this thread. None of them quite met my needs, so I figured I'd contribute my own solution as well. Hopefully others find it valuable.
My Setup
I am running Python 3.10 on Ubuntu 22.04.2. I am using
aiohttp
to make HTTP requests asynchronously.I am making an HTTP request to a piece of hardware on my internal LAN, and I cannot update this hardware to simply stop using the insecure SSL renegotiation.
My Approach
I created a custom SSL context, and then passed in the SSL OP flag 'SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION'. I got this flag from here: List of SSL OP Flags
If you also need to disable SSL verification (in the case of development testing for example), you can add the following two lines to your custom_ssl_context:
现在我解决问题 - [SSL错误不安全的遗产重新谈判禁用]
或(由sslerror引起(sslerror(1,'[ssl:unsafe_legacy_renegotiation_disabled]不安全的遗产重新接触(_SSSL.C:1007)'))))))))))))))))
下面的参考链接:但是不使用它只是尝试理解问题
()
使用以下代码:
Now I resolve issue it - [SSL error unsafe legacy renegotiation disabled]
or (Caused by SSLError(SSLError(1, '[SSL: UNSAFE_LEGACY_RENEGOTIATION_DISABLED] unsafe legacy renegotiation disabled (_ssl.c:1007)')))
reference link below : but it's not used just try to understand the problem
(SSL error unsafe legacy renegotiation disabled)
use below code :
对我来说,当我将python降级到
v3.10.8。
(如果您在Docker容器中遇到问题,请在下面阅读)时,
它有效,我在我的Docker Image中,我使用的是使用V3的Alpine-10 .10.9。由于我无法使用v3.10.8获得高山,因此我使用了3.10.8-slim-bullseye。
For me, it worked when I downgraded python to
v3.10.8.
(If you are facing the issue in docker container, read below)
In my docker image, I was using alpine-10 which was using v3.10.9. Since I couldn't get alpine with v3.10.8, I used 3.10.8-slim-bullseye.