无法获取网址

时间:2017-12-06 04:56:42

标签: python ssl

这不重复。我已经阅读了网上的所有回复。

每当我尝试通过终端连接到网站时,我都会收到错误消息。许多解决方案都说首先尝试安装certifi然后再尝试,但我不能这样做,因为那时我必须连接到https://pypi.python.org/simple/certifi/。我也试过--trusted-host,但我仍然收到错误。

如果我尝试在Python 3.6文件夹中运行Install Certificates.command,则出现以下错误:

/Applications/Python\ 3.6/Install\ Certificates.command ; exit;
 -- pip install --upgrade certifi
Collecting certifi
  Could not fetch URL https://pypi.python.org/simple/certifi/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:777) - skipping
  Could not find a version that satisfies the requirement certifi (from versions: )
No matching distribution found for certifi
Traceback (most recent call last):
  File "<stdin>", line 44, in <module>
  File "<stdin>", line 25, in main
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6', '-E', '-s', '-m', 'pip', 'install', '--upgrade', 'certifi']' returned non-zero exit status 1.
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

如果我尝试使用url lib连接python doc然后尝试在终端中运行python doc,我也会收到SSL错误。我还要提一下这是一个全新的问题。我昨天运行了相同的脚本并且运行正常。

版本:

Python 3.6
numpy==1.13.3
ortools==6.6.4656
pandas==0.21.0
protobuf==3.5.0.post1
python-dateutil==2.6.1
pytz==2017.3
six==1.11.0
OpenSSH_7.4p1, LibreSSL 2.5.0

1 个答案:

答案 0 :(得分:3)

在脚本中添加以下行并执行脚本。可能会解决你的问题。

import ssl
ssl._create_default_https_context = ssl._create_unverified_context