Updated requests fix to match with pyinstaller later. #309

This commit is contained in:
Manuel Cortez 2019-10-03 17:18:06 -05:00
parent a58187e5f7
commit 073ccbf6c7
2 changed files with 13 additions and 28 deletions

View File

@ -13,7 +13,7 @@ def setup():
if hasattr(sys, "frozen"):
fix_libloader.fix()
fix_win32com.fix()
fix_requests.fix(True)
else:
fix_requests.fix(False)
fix_requests.fix()
# else:
# fix_requests.fix(False)
fix_urllib3_warnings.fix()

View File

@ -1,27 +1,12 @@
from __future__ import unicode_literals
from requests import certs, utils, adapters
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import requests
import paths
import config
import requests.sessions
orig_session_init=requests.sessions.Session.__init__
import os
import logging
log = logging.getLogger("fixes.fix_requests")
def patched_where():
return paths.app_path(u"cacert.pem")
def fix(frozen):
if frozen==True:
certs.where=patched_where
utils.DEFAULT_CA_BUNDLE_PATH=patched_where()
adapters.DEFAULT_CA_BUNDLE_PATH=patched_where()
requests.sessions.Session.__init__=patched_session_init
requests.Session.__init__=patched_session_init
requests.session.__init__=patched_session_init
def patched_session_init(self):
orig_session_init(self)
if config.app["proxy"]["server"] != "" and config.app["proxy"]["port"] != "" and config.app["proxy"]["type"] in config.proxyTypes:
self.proxies={"http":"{0}://{1}:{2}/".format(config.app["proxy"]["type"], config.app["proxy"]["server"], config.app["proxy"]["port"]),
"https": "{0}://{1}:{2}/".format(config.app["proxy"]["type"], config.app["proxy"]["server"], config.app["proxy"]["port"])}
if config.app["proxy"]["user"] != "" and config.app["proxy"]["password"] != "":
self.proxies={"http": "{0}://{1}:{2}@{3}:{4}/".format(config.app["proxy"]["type"], config.app["proxy"]["user"], config.app["proxy"]["password"], config.app["proxy"]["server"], config.app["proxy"]["port"]),
"https": "{0}://{1}:{2}@{3}:{4}/".format(config.app["proxy"]["type"], config.app["proxy"]["user"], config.app["proxy"]["password"], config.app["proxy"]["server"], config.app["proxy"]["port"])}
def fix():
log.debug("Applying fix for requests...")
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(paths.app_path(), "certifi", "cacert.pem")#.encode(paths.fsencoding)
# log.debug("Changed CA path to %s" % (os.environ["REQUESTS_CA_BUNDLE"]))#.decode(paths.fsencoding)))