>> requests.get("https:/-6ren">
gpt4 book ai didi

ssl - 为什么在向 sandbox.example.com 等任何子域发送请求时会出现此 SSL 错误?

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

>>> import requests
>>> requests.get("https://api.example.com/index.php")
<Response [200]>

>>> requests.get("https://sandbox.example.com/index.php")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 385, in send
raise SSLError(e)
SSLError: hostname 'sandbox.example.com' doesn't match either of 'example.com', 'account.example.com', 'api.example.com', 'secure.example s.com'

为什么在 https://sandbox.example.com/index.phphttps://api.example.com/index.php 都出现此错误 在浏览器上工作正常吗?

最佳答案

Python3 的 SSL 模块包含对 SNI 的原生支持.此支持尚未移植到 Python2。远程服务器可能依赖于 SNI 来为您提供正确的证书,因此会出现错误。

有关在 Python2 上将 SNI 与请求一起使用的信息,请参阅此 Stack Overflow answer .

关于ssl - 为什么在向 sandbox.example.com 等任何子域发送请求时会出现此 SSL 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27156034/

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