惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyberwarzone
Cyberwarzone
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
The Hacker News
The Hacker News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
D
Docker
H
Hacker News: Front Page
Recent Announcements
Recent Announcements
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
P
Proofpoint News Feed
Security Latest
Security Latest
AI
AI
I
InfoQ
Google DeepMind News
Google DeepMind News
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Scott Helme
Scott Helme
N
News | PayPal Newsroom
Y
Y Combinator Blog
V
Visual Studio Blog
Latest news
Latest news
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
WordPress大学
WordPress大学
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
TaoSecurity Blog
TaoSecurity Blog
S
Security @ Cisco Blogs
D
DataBreaches.Net
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
T
Troy Hunt's Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Heimdal Security Blog
美团技术团队
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Security Affairs
T
Threat Research - Cisco Blogs
Webroot Blog
Webroot Blog
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏

博客园 - HorseShoe2016

Ethereum 学习笔记 ---- Solidity 数据位置(Calldata, Memory, Storage)编码与布局全解析 vscode 禁用警告提示音 浏览器加载 HTML 页面并执行 Javascript 的流程图 Ethereum学习笔记 ---- 多重继承中的 C3线性化算法 Ethereum学习笔记 ---- 使用 Remix 调试功能理解 bytes 在 memory 中的布局 Ethereum学习笔记 ---- 通过 Event 学习《合约ABI规范》 Javascript: Blob, File/FileReader, ArrayBuffer, ReadableStream, Response 转换方法 vscode 无法调试 golang testify suite 中的单个 test 的解决办法 纯js实现 vue 组件 与 vue 单文件组件对比 一个简单的 indexedDB 应用示例 html 元素的 onEvent 与 addEventListener vue3 defineComponent: 使用纯 Javascript 定义组件 vue3 动态编译组件失败:Component provided template option but runtime compilation is not supported in this build of Vue Javascript Object 中,isExtensible/isSealed/isFrozen 的对比 mini-vue: 响应式数据的实现 手写Promise vscode vue 插件与 emmet、tailwind css 插件冲突的解决方案 CentOS7 源码编译安装 Python 3.8.10,开启 SSL 功能 Protocol Buffer Go (proto3) - macos 搭建 protocol buffer 环境 + Encoding 实验
Python 安装依赖包,出现 ssl.SSLCertVerificationError 的问题,解决方法
HorseShoe2016 · 2023-06-21 · via 博客园 - HorseShoe2016

问题描述

CentOS7环境,已安装 Python3.8.10。

最近项目开发,需要切换 solidity 版本,参考开发文档,需要执行如下命令

pip install solc-select==0.2.0

# 安装指定版本solc
solc-select install <solc版本号>

# 切换solc版本
solc-select use <solc版本号>

先使用 pip install solc-select==0.2.0 命令成功安装了 solc-select,然后执行 solc-select install 查看有哪些可用的 solc 版本,遇到如下问题:

$ solc-select install
Available versions to install:
Traceback (most recent call last):
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/local/python3/python3.8.10/lib/python3.8/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/python3/python3.8.10/lib/python3.8/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/python3/python3.8.10/lib/python3.8/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/python3/python3.8.10/lib/python3.8/http/client.py", line 1007, in _send_output
    self.send(msg)
  File "/usr/local/python3/python3.8.10/lib/python3.8/http/client.py", line 947, in send
    self.connect()
  File "/usr/local/python3/python3.8.10/lib/python3.8/http/client.py", line 1421, in connect
    self.sock = self._context.wrap_socket(self.sock,
  File "/usr/local/python3/python3.8.10/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/usr/local/python3/python3.8.10/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/usr/local/python3/python3.8.10/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/buaa/.local/bin/solc-select", line 8, in <module>
    sys.exit(solc_select())
  File "/home/buaa/.local/lib/python3.8/site-packages/solc_select/__main__.py", line 24, in solc_select
    for version in sorted(get_installable_versions()):
  File "/home/buaa/.local/lib/python3.8/site-packages/solc_select/solc_select.py", line 78, in get_installable_versions
    return set(get_available_versions()) - set(installed_versions())
  File "/home/buaa/.local/lib/python3.8/site-packages/solc_select/solc_select.py", line 82, in get_available_versions
    list_json = urllib.request.urlopen(url).read()
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 1397, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
  File "/usr/local/python3/python3.8.10/lib/python3.8/urllib/request.py", line 1357, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)>

解决办法

网上搜索 'ssl.SSLCertVerificationError',看到帖子:

python爬虫ssl.SSLCertVerificationError解决办法

根据其中的

方法二:

全局取消证书验证,简易方便,但对整个项目可能会出现安全性的相关问题。

import ssl
ssl._create_default_https_context = ssl._create_unverified_context

联想到可以手动修改 Python 中的 ssl 模块。

于是进入 Python3.8.10 的安装目录,搜索 ssl.py,打开该文件,手动修改之

$ cd /usr/local/python3/python3.8.10

$ find . -name ssl.py
./lib/python3.8/ssl.py

$ sudo vim  ./lib/python3.8/ssl.py

找到

_create_default_https_context = create_default_context

这一行,注释掉,然后修改为

_create_default_https_context = _create_unverified_context

再次执行  solc-select install,就正常了:

$ solc-select install
Available versions to install:
0.4.10
0.4.11
0.4.12
0.4.13
0.4.14
0.4.15
0.4.16
0.4.17
0.4.18
0.4.19
0.4.20
0.4.21
0.4.22
0.4.23
0.4.24
0.4.25
0.4.26
0.5.0
0.5.1
0.5.10
0.5.11
0.5.12
0.5.13
0.5.14
0.5.15
0.5.16
0.5.17
0.5.2
0.5.3
0.5.4
0.5.5
0.5.6
0.5.7
0.5.8
0.5.9
0.6.0
0.6.1
0.6.10
0.6.11
0.6.12
0.6.2
0.6.3
0.6.4
0.6.5
0.6.6
0.6.7
0.6.8
0.6.9
0.7.0
0.7.1
0.7.2
0.7.3
0.7.4
0.7.5
0.7.6
0.8.0
0.8.1
0.8.10
0.8.11
0.8.12
0.8.13
0.8.14
0.8.15
0.8.16
0.8.17
0.8.18
0.8.19
0.8.2
0.8.20
0.8.3
0.8.4
0.8.5
0.8.6
0.8.7
0.8.8
0.8.9

注意事项

_create_default_https_context = _create_unverified_context

这一行代码的作用是取消 python 访问 https 服务器时的证书验证步骤,这是存在安全风险的;自己临时需要做的工作完成以后,就应该将 ssl.py 修改回原来的样子。


2023.06.14 Wed 14:45