国内 google depot_tools gclient SSLError hostname 错误解决

来源:转载

由于众所周知的原因,google的服务器在国内是被墙的。

我需要下载webrtc的源代码,根据google的readme,我需要使用depot_tools gclient命令。

由于*.googlesource.com 和*.googleapis.com等很多url在此repo中被使用,而我们用工具比如XX-NET寻找到的可用gws IP的证书的hostname通常并不能匹配例如*.googleapis.com 这些域名,api系列有自己的域名,但并不是那么容易找到并使用,所以不得不使用gws的IP。

但是执行命令会报告 SSLError hostname ******* 的错误。

我们修改depot_tools/bootstrap/bootstrap.pyls 方法,在构造url请求时使用

data = requests.get(STORAGE_URL, params=dict( prefix=prefix, fields='items(name,md5Hash)' )).json()

变为

data = requests.get(STORAGE_URL, params=dict( prefix=prefix, fields='items(name,md5Hash)' ),verify=False).json()

还有一处

depot_tools/bootstrap/virtualenv/virtualenv_support/pip-6.0-py2.py3-none-any.whl

pip/download.py

修改方法def _download_http_url(link, session, temp_dir):

由:

try:resp = session.get(target_url,# We use Accept-Encoding: identity here because requests# defaults to accepting compressed responses. This breaks in# a variety of ways depending on how the server is configured.# - Some servers will notice that the file isn't a compressible# file and will leave the file alone and with an empty# Content-Encoding# - Some servers will notice that the file is already# compressed and will leave the file alone and will add a# Content-Encoding: gzip header# - Some servers won't notice anything at all and will take# a file that's already been compressed and compress it again# and set the Content-Encoding: gzip header# By setting this to request only the identity encoding We're# hoping to eliminate the third case. Hopefully there does not# exist a server which when given a file will notice it is# already compressed and that you're not asking for a# compressed file and will then decompress it before sending# because if that's the case I don't think it'll ever be# possible to make this work.headers={"Accept-Encoding": "identity"},stream=True,)resp.raise_for_status()except requests.HTTPError as exc:

变为

try:resp = session.get(target_url,# We use Accept-Encoding: identity here because requests# defaults to accepting compressed responses. This breaks in# a variety of ways depending on how the server is configured.# - Some servers will notice that the file isn't a compressible# file and will leave the file alone and with an empty# Content-Encoding# - Some servers will notice that the file is already# compressed and will leave the file alone and will add a# Content-Encoding: gzip header# - Some servers won't notice anything at all and will take# a file that's already been compressed and compress it again# and set the Content-Encoding: gzip header# By setting this to request only the identity encoding We're# hoping to eliminate the third case. Hopefully there does not# exist a server which when given a file will notice it is# already compressed and that you're not asking for a# compressed file and will then decompress it before sending# because if that's the case I don't think it'll ever be# possible to make this work.headers={"Accept-Encoding": "identity"},stream=True,verify=False,)resp.raise_for_status()except requests.HTTPError as exc:

核心思路是使用

verify=False 参数跳过SSL证书校验

分享给朋友:
您可能感兴趣的文章:
随机阅读: