【发布时间】:2021-10-02 19:08:51
【问题描述】:
我的 Python 代码(位于 AWS EC2 框中的 Docker 映像上)正在使用请求库来尝试获取网页的内容。如果我做像requests.get(url='https://google.com', verify=False).text 这样简单的事情,它将返回以下内容,值得注意的是“fortiadc_error_page”。
/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py:1013: InsecureRequestWarning: Unverified HTTPS request is being made to host 'google.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
warnings.warn(
<!DOCTYPE html>\n<html>\t\n\t<head>\n\t</head>\n\t<body>\n\t\t<iframe src="/fortiadc_error_page/index.html" frameborder="0" width="100%" scrolling="no" onload="function resizeIframe(obj) {\n\t obj.style.height = obj.contentWindow.document.body.scrollHeight + 10 + \'px\';\n\t };resizeIframe(this)"></iframe>\n\t</body>
我从请求中删除 verify,如下所示:requests.get(url='https://google.com').text,然后我返回:ssl.SSLCertVerificationError: ("hostname 'google.com' doesn't match either of '*.fortinet.com', 'fortinet.com'",)
有人知道如何解决这些错误吗?我使用 RHEL 8 AMI 部署了它,所以这里不应该有任何特殊的安全问题。我已经开放了 443 和 80 端口。
这很奇怪,因为我可以这样做 requests.get('https://stackoverflow.com') 并且工作正常。但是 Google 和 CNN 失败了,我真正想从中拉出来的网站也失败了。
更详细一点 - 我再次在 AWS 上部署了一个 EC2,并在其上安装了 K3D。在 K3D 上,我安装了一组 Kubernetes 清单文件,其中包括一个 cronjob。当我运行那个 cronjob 时,它在一个 docker 映像上运行,该映像具有 Python 并运行请求代码,但失败了。
【问题讨论】:
-
您的网络路径中的某些东西似乎错误地拦截了传出的网络流量。
verify=False告诉requests模块“我可以和这个fortinet 的东西交谈并给它我的谷歌凭据”;你几乎肯定不想设置它。
标签: python python-3.x docker shell kubernetes