查看: 1705|回复: 3

PIP install failed and connection error: [SSL: certificate certificate faile

[复制链接]

10

主题

72

帖子

180

积分

注册会员

Rank: 2

积分
180
发表于 2018-9-18 17:03:30 | 显示全部楼层 |阅读模式
我是Python的新手,并尝试在Windows 7上pip install linkchecker。一些注意事项:
•        pip安装失败,无论封装。例如,pip install scrapy也会导致SSL错误。
•        Python 3.4.1的Vanilla安装包括pip 1.5.6。我尝试做的第一件事是安装linkchecker。Python 2.7已经安装,它随ArcGIS一起提供。> pip search linkchecker作品。也许这是因为pip搜索不会验证网站的SSL证书。
•        我在公司网络中,但我们没有通过代理来访问互联网。
•        每台公司计算机(包括我的计算机)都有一个受信任的根证书颁发机构,其使用原因有多种,包括启用监控TLS流量到https://google.com。不确定这与它有什么关系。
以下是运行后我的pip.log的内容pip install linkchecker:
  1. Downloading/unpacking linkchecker
  2.   Getting page https://pypi.python.org/simple/linkchecker/
  3.   Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
  4.   Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
  5.   Getting page https://pypi.python.org/simple/
  6.   Could not fetch URL https://pypi.python.org/simple/: connection error: HTTPSConnectionPool(host='pypi.python.org', port=443): Max retries exceeded with url: /simple/ (Caused by <class 'http.client.CannotSendRequest'>: Request-sent)
  7.   Will skip URL https://pypi.python.org/simple/ when looking for download links for linkchecker
  8.   Cannot fetch index base URL https://pypi.python.org/simple/
  9.   URLs to search for versions for linkchecker:
  10.   * https://pypi.python.org/simple/linkchecker/
  11.   Getting page https://pypi.python.org/simple/linkchecker/
  12.   Could not fetch URL https://pypi.python.org/simple/linkchecker/: connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)
  13.   Will skip URL https://pypi.python.org/simple/linkchecker/ when looking for download links for linkchecker
  14.   Could not find any downloads that satisfy the requirement linkchecker
  15. Cleaning up...
  16.   Removing temporary dir C:\Users\jcook\AppData\Local\Temp\pip_build_jcook...
  17. No distributions at all found for linkchecker
  18. Exception information:
  19. Traceback (most recent call last):
  20.   File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
  21.     status = self.run(options, args)
  22.   File "C:\Python34\lib\site-packages\pip\commands\install.py", line 278, in run
  23.     requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  24.   File "C:\Python34\lib\site-packages\pip\req.py", line 1177, in prepare_files
  25.     url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  26.   File "C:\Python34\lib\site-packages\pip\index.py", line 277, in find_requirement
  27.     raise DistributionNotFound('No distributions at all found for %s' % req)
  28. pip.exceptions.DistributionNotFound: No distributions at all found for linkchecker
复制代码

回复

使用道具 举报

11

主题

80

帖子

199

积分

注册会员

Rank: 2

积分
199
发表于 2018-9-18 17:08:14 | 显示全部楼层
可以通过设置pypi.org和files.pythonhosted.org作为可信主机来忽略SSL错误。
$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>
注意:在2018年4月的某个时间,Python包索引已从中迁移pypi.python.org到pypi.org。这意味着使用旧域的“trusted-host”命令不再起作用。
永久修复
自从pip 10.0发布以来,你应该能够通过pip自我升级来永久修复它:
$ pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip setuptools
或者只是重新安装它以获得最新版本:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
(...然后get-pip.py使用相关的Python解释器运行)。
pip install <otherpackage>应该在此之后可以工作。如果没有,那么您将需要做更多,如下所述。
________________________________________
您可能希望将可信主机和代理添加到配置文件中。
pip.ini(Windows)或pip.conf(unix)
[global]
trusted-host = pypi.python.org
               pypi.org
               files.pythonhosted.org
________________________________________
替代解决方案(不太安全)
大多数答案可能会带来安全问题。
有助于轻松安装大多数python包的两个解决方法是:
•        使用easy_install:如果你真的很懒,不想浪费太多时间,请使用easy_install <package_name>。请注意,找不到某些包或会出现小错误。
•        使用Wheel:下载python包的Wheel并使用pip命令pip install wheel_package_name.whl安装包。
回复

使用道具 举报

9

主题

74

帖子

185

积分

注册会员

Rank: 2

积分
185
发表于 2018-9-18 17:09:09 | 显示全部楼层
您可以使用此参数指定证书:
  1. pip --cert /etc/ssl/certs/FOO_Root_CA.pem install linkchecker
复制代码

请参阅:文档»参考指南»pip
如果指定您公司的根证书不起作用,那么CURL可能会起作用:http://curl.haxx.se/ca/cacert.pem
您必须使用PEM文件而不是CRT文件。如果您有CRT文件,则需要将文件转换为PEM
另请检查:SSL证书验证。
回复

使用道具 举报

11

主题

63

帖子

159

积分

注册会员

Rank: 2

积分
159
发表于 2018-9-18 17:10:33 | 显示全部楼层
--trusted-host
例如,在这种情况下,可以这样做
  1. pip install --trusted-host pypi.python.org linkchecker
复制代码

pem文件(或其他任何内容)是不必要的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表