gpt4 book ai didi

Python 请求本地地址抛出 SSLError

转载 作者:太空宇宙 更新时间:2023-11-03 13:35:40 26 4
gpt4 key购买 nike

我有一个带有 letsencrypt 证书的 python3 django 网站

一切正常,除了使用 python 请求到本地地址:

response = requests.post('http://127.0.0.1:8100', data=data)

而且它有非常奇怪的行为:

有时我得到 200,但在 supervisorctl restart mywebsite 之后它会抛出 SSLError

然后我做了:

response = requests.post('http://127.0.0.1:8100', data=data, verify=True)

一切都很好,直到我再次让 supervisorctl restart mywebsite,它抛出 SSLError O_o,现在只适用于

response = requests.post('http://127.0.0.1:8100', data=data)

所以最终的工作代码是:

try:
response = requests.post('http://127.0.0.1:8100', data=data, verify=True)
except:
try:
response = requests.post('http://127.0.0.1:8100', data=data)
except:
response = requests.post('http://127.0.0.1:8100', data=data, verify=False)

显然这不是最好的计划)

非常感谢您的建议

最佳答案

很可能您的 Web 应用发出从 http://https:// 的重定向。您可以通过使用 curl -v 查看响应 header 来验证这一点。重定向后,您可能会因为使用 localhost 而不是域名而收到 SSL 错误:

You can't get a certificate for localhost; the certificate authority is only able to issue certificates for publicly-visible, globally-unique domain names. localhost doesn't count, and the certificate authority isn't allowed to issue certs for it. -- https://community.letsencrypt.org/t/can-i-test-lets-encrypt-client-on-localhost/15627

编辑:

尝试使用 verify=Falsehttps:// URL 执行初始请求。

关于Python 请求本地地址抛出 SSLError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41185199/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com