亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

修復使用py2exe(或PyInstaller)編譯的exe中的SSL證書錯誤

修復使用py2exe(或PyInstaller)編譯的exe中的SSL證書錯誤

慕田峪7331174 2021-03-29 08:55:03
我剛剛完成了一個Python程序的測試,該程序涉及登錄網站并需要設置CSRF cookie。我嘗試將其打包為exepy2exe并收到套接字錯誤。我嘗試使用時遇到相同的問題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\build\pyi.win32\autoresponder\out00-PYZ.pyz\requests.sessions", line 350, in get  File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\build\pyi.win32\autoresponder\out00-PYZ.pyz\requests.sessions", line 338, in request  File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\build\pyi.win32\autoresponder\out00-PYZ.pyz\requests.sessions", line 441, in send  File "C:\pyinstaller-2.0\pyinstaller-2.0\autoresponder\build\pyi.win32\autoresponder\out00-PYZ.pyz\requests.adapters", line 331, in sendrequests.exceptions.SSLError: [Errno 185090050] _ssl.c:336: error:0B084002:x509certificate routines:X509_load_cert_crl_file:system lib這是否意味著問題出在requests.adapters哪里?如果是這樣,我可以在已安裝的Python軟件包中對其進行編輯以在其他地方查找cacert.pem,用py2exe或重建我的exe PyInstaller,然后在已安裝的Python版本中將其更改回嗎?
查看完整描述

3 回答

?
拉風的咖菲貓

TA貢獻1995條經驗 獲得超2個贊

如果使用“請求”模塊,則可以輕松解決。


1)將以下代碼放在使用“ requests”模塊的主python文件中


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

2)在存在exe的可分發文件夾中,創建一個名為“ certifi”的文件夾,并將“ cacert.pem”文件放入其中。


3)您可以通過以下方式找到“ cacert.pem”文件


pip install certifi


import certifi

certifi.where()

太棒了..現在您的可分發內容包括必要的證書,以驗證ssl調用。


查看完整回答
反對 回復 2021-04-02
  • 3 回答
  • 0 關注
  • 329 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號