I have a program that pools ad stats from different marketing systems. Everything works fine untill i convert it to the .exe format and run it.
Exception in
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
def override_where():
""" overrides certifi.core.where to return actual location of cacert.pem"""
# change this to match the location of cacert.pem
return os.path.abspath("cacert.pem")
# is the program compiled?
if hasattr(sys, "frozen"):
import certifi.core
os.environ["REQUESTS_CA_BUNDLE"] = override_where()
certifi.core.where = override_where
# delay importing until after where() has been replaced
import 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()
This might be 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 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
.
Hope this helps.