【发布时间】:2021-12-17 06:47:27
【问题描述】:
我刚刚完成了一个 Python 程序的测试,该程序涉及登录网站并需要设置 CSRF cookie。我尝试使用py2exe 将其打包为exe,但出现套接字错误。当我尝试使用PyInstaller 时,我遇到了同样的问题。谷歌搜索 Errno 我发现其他几个人有同样的问题,所以我知道问题与 SLL 证书的位置有关。
这是我的 site_agent 类,包括日志调用。
class site_agent:
self.get_params()
URL = root_url + '/accounts/login/'
# Retrieve the CSRF token first
self.agent = requests.session()
self.agent.get(URL) # retrieves the cookie # This line throws the error
self.csrftoken = self.agent.cookies['csrftoken']
# Set up login data including the CSRF cookie
login_data = {'username': self.username,
'password': self.password,
'csrfmiddlewaretoken' : self.csrftoken}
# Log in
logging.info('Logging in')
response = self.agent.post(URL, data=login_data, headers=hdr)
错误出现在self.agent.get(URL) 行,Traceback 显示:
Traceback (most recent call last):
File "<string>", line 223, in <module>
File "<string>", line 198, in main
File "<string>", line 49, in __init__
File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\b
uild\pyi.win32\autoresponder\out00-PYZ.pyz\requests.sessions", line 350, in get
File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\b
uild\pyi.win32\autoresponder\out00-PYZ.pyz\requests.sessions", line 338, in requ
est
File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\b
uild\pyi.win32\autoresponder\out00-PYZ.pyz\requests.sessions", line 441, in send
File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\b
uild\pyi.win32\autoresponder\out00-PYZ.pyz\requests.adapters", line 331, in send
requests.exceptions.SSLError: [Errno 185090050] _ssl.c:336: error:0B084002:x509
certificate routines:X509_load_cert_crl_file:system lib
这是否意味着问题出在requests.adapters?
如果是这样,我是否可以在已安装的 Python 包中对其进行编辑以在其他地方查找 cacert.pem,使用 py2exe 或 PyInstaller 重建我的 exe,然后在我安装的 Python 版本中将其改回?
编辑
在使用PyInstaller 编译并在所有requests.get() 和requests.post() 调用中设置verify=False 后,我现在可以运行程序。但 SSL 的存在是有原因的,我真的希望能够在让任何人使用该工具之前修复此错误。
【问题讨论】:
标签: python ssl py2exe python-requests pyinstaller