在 python-requests 中发出经过验证的 SSL 请求时,有没有办法覆盖主机标头?

use*_*465 5 python python-2.7 python-requests

我想覆盖 python 请求中的主机标头。主要是这样我可以在失败时使用不同的解析 IP 重试。但在用标头覆盖主机时,我似乎无法验证主机名。

import requests
import socket

host, alias, ip = socket.gethostbyname_ex("www.google.com")
requests.get("https://%s" % ip[0], headers={"Host": "www.google.com"})
Run Code Online (Sandbox Code Playgroud)

requests.exceptions.SSLError:主机名“74.125.196.147”与“www.google.com”不匹配