python 中requests 模块用py2exe生成exe后SSL certificate exception的问题

本文解决Python环境下因SSL证书问题导致的请求失败。通过修改环境变量、创建certifi文件夹并放置cacert.pem文件,确保requests模块正常运行。
[('system library', 'fopen', 'No such process'), ('BIO routines', 'BIO_new_file', 'no such file'), ('x509 certificate routines', 'X509_load_cert_crl_file', 'system lib')]

解决:
1) Place the below code in your main python file where “requests” module is used

os.environ['REQUESTS_CA_BUNDLE'] = "certifi/cacert.pem"

2) Within your distributable folder where exe is present, create a folder called “certifi” and place the “cacert.pem” file within it.

3) You can find the “cacert.pem” file by

pip install certifi

import certifi
certifi.where()

or you can copy it from python installation path, e.g. C:\Python27\Lib\site-packages\pip\_vendor\certifi

following traceback to the conda GitHub issue tracker at: https://github.com/conda/conda/issues Include the output of the command 'conda info' in your report. Traceback (most recent call last): File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen body=body, headers=headers) File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 341, in _make_request self._validate_conn(conn) File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn conn.connect() File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connection.py", line 238, in connect ssl_version=resolved_ssl_version) File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/util/ssl_.py", line 279, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/home/pi/miniconda3/lib/python3.4/ssl.py", line 365, in wrap_socket _context=self) File "/home/pi/miniconda3/lib/python3.4/ssl.py", line 583, in __init__ self.do_handshake() File "/home/pi/miniconda3/lib/python3.4/ssl.py", line 810, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/adapters.py", line 370, in send timeout=timeout File "/home/pi/miniconda3/lib/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 574, in urlopen raise SSLError(e) requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:600) During handling of the above exception, another exception occurred: Traceback (most recent call last): Fi
最新发布
09-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值