Python Requests Can't Find A Folder With A Certificate When Converted To .exe
Solution 1:
I ran into this problem as well. It looks like it comes from the certificate bundle cacert.pem
not being included in the requests
package directory when the program is compiled. The requests
module uses the function certifi.core.where
to determine the location of cacert.pem
. Overriding this function and overriding the variables set by this function seems to fix the problem.
I added this code to the beginning of my program:
import sys, os
defoverride_where():
""" overrides certifi.core.where to return actual location of cacert.pem"""# change this to match the location of cacert.pemreturn os.path.abspath("cacert.pem")
# is the program compiled?ifhasattr(sys, "frozen"):
import certifi.core
os.environ["REQUESTS_CA_BUNDLE"] = override_where()
certifi.core.where = override_where
# delay importing until after where() has been replacedimport requests.utils
import requests.adapters
# replace these variables in case these modules were# imported before we replaced certifi.core.where
requests.utils.DEFAULT_CA_BUNDLE_PATH = override_where()
requests.adapters.DEFAULT_CA_BUNDLE_PATH = override_where()
Solution 2:
This might be an issue with requests
package.
I solved this by manually copying the cacert.pem
file from /lib/site-packages/certifi
to /lib/site-packages/requests
If you want to fix this issue with .exe
, then copy cacert.pem
file from /lib/site-packages/certifi
to dist/library.zip/certifi/
.
I am considering you have created exe
using py2exe
, where py2exe
will create library.zip
under dist/
which contains of all script dependencies. I don't know if other exe
converters create library.zip
.
Solution 3:
If you want to disable certificate verification, you can use the verify=False
parameter in requests.get()
:
requests.get('https://example.com', verify=False)
Post a Comment for "Python Requests Can't Find A Folder With A Certificate When Converted To .exe"