Właśnie skończyłem testować program w języku Python, który wymaga logowania do witryny i wymaga ustawienia pliku cookie CSRF. Próbowałem pakować go jako exe przy użyciu py2exe
i otrzymałem błąd gniazda. Mam ten sam problem, gdy próbuję z PyInstaller
. Googling the Errno Znalazłem kilka osób z tym samym problemem, więc wiem, że problem dotyczy lokalizacji certyfikatów SLL.Naprawianie błędu certyfikatu SSL w exe skompilowanego z py2exe (lub PyInstaller)
To jest moja klasa site_agent
, w tym połączenia rejestrowania.
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)
Błąd pojawia się w linii self.agent.get(URL)
a Traceback pokazuje:
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
Czy oznacza to, że problem jest w requests.adapters
? Jeśli tak, czy mogę po prostu edytować go w moich zainstalowanych pakietach Pythona, aby wyszukać cacert.pem gdzieś indziej, przebudować mój exe z py2exe
lub PyInstaller
, a następnie zmienić go z powrotem w mojej zainstalowanej wersji Pythona?
EDIT
Mam teraz uruchomiony program po kompilacji z PyInstaller
i ustawienie verify=False
we wszystkich requests.get()
i requests.post()
połączeń. Ale SSL istnieje z jakiegoś powodu i naprawdę chciałbym móc naprawić ten błąd, zanim pozwolę komuś korzystać z tego narzędzia.
http://stackoverflow.com/a/21206079/538284 –