python - 无法获取网址

标签 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 文档中连接,然后尝试在终端中运行 python 文档,我也会收到 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

最佳答案

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

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

关于python - 无法获取网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47667044/

相关文章:

ssl - 无法激活与 Django 和 Nginx 的 HTTPS 链接

java - 如何配置 RabbitMQ 客户端以使用 SSL?

java - SOAP 适配器的 SSL 握手失败

python - 如何在 pandas 数据框中使用 groupby 查找描述性统计数据

python - 木星 |如何旋转 3D 图形

Python - 如何替换列表中的字符串?

java - 找不到 SNIServerName 类

ssl - 本地主机上的 Websocket 通过 https ://problems

python - 将数据帧转换为热图矩阵?

python - 在 pymongo 的字典中包含 NumberInt