error: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

python下载文件到指定目录报错

error: 

如何解决?用如下的脚本代码:

  1. 链接要改成http开头的,不是https
  2. 添加ssl._create_default_https_context = ssl._create_unverified_context
  3. ProxyHandler要使用代理

import ssl
ssl._create_default_https_context = ssl._create_unverified_context
proxy_handler = urllib.request.ProxyHandler({'http': os.environ['http_proxy'], 'https': os.environ['http_proxy']})
downloader = urllib.request.build_opener(proxy_handler)
urllib.request.install_opener(downloader)

DATA_UTILS_URL = "http://raw.githubusercontent.com/google-research/simclr/master/tf2/data_util.py"
urllib.request.urlretrieve(DATA_UTILS_URL, output_path)

你可能感兴趣的:(ssl,网络协议,网络)