我试图在.exe中制作.py。在.py应用程序工作正常,但在我使用py2exe在.exe中构建它后,我收到此错误:
Traceback (most recent call last):
File "filename.py", line 210, in <module>
File "requests\api.pyc", line 55, in get
File "requests\api.pyc", line 44, in requests
File "requests\sessions.pyc", line 461, in request
File "requests\sessions.pyc", line 567, in send
File "requests\adapters.pyc", line 399, in send
requests.exceptions.SLLError: [Errno 185090050] _ssl.c:344: error: 0B084002:x509 certificate routines: X509_load_cert_crl_file:system lib
文件中的第210行是
r2 = requests.get('https://www.hitbox.tv/api/chat/servers', timeout=timeoutDefault)
setup.py是这样的:
from distutils.core import setup
import py2exe
setup(console=['filename.py'])
我如何解决这个问题?
答案 0 :(得分:5)
requests
模块(或其下面的实际urllib3
)无法打开CA证书文件。
如果您不想验证服务器的证书,可以将呼叫更改为:
r2 = requests.get('https://www.hitbox.tv/api/chat/servers',
timeout=timeoutDefault, verify=False)
如果您关心证书(并且您应该),请确保CA证书文件与您的应用程序捆绑在一起。根据{{1}}文档:
您还可以验证CA_BUNDLE文件的路径是否为私有 证书。您还可以设置REQUESTS_CA_BUNDLE环境变量。
如果设置,请求也可以忽略验证SSL证书 验证为假。
见这里:http://docs.python-requests.org/en/latest/user/advanced/#ssl-cert-verification
答案 1 :(得分:1)
我通过猴子修补requests
来解决这个问题,以通过cacert.pem
:
def _monkey_patch_requests():
orig_send = HTTPAdapter.send
def _send_no_verify(self, request, stream=False, timeout=None, verify=True, cert=None, proxies=None):
return orig_send(self, request, stream, timeout, 'cacert.pem' if verify else False, cert, proxies)
HTTPAdapter.send = _send_no_verify
_monkey_patch_requests()
并将<Python>/Lib/site-packages/certifi/cacert.pem
复制到dist
。