# using pysintaller "frozen" with requests library receves an SSLError (x509 open ssl crl)
# make sure you copy the cacert.pem file up to the same location where your .py file is in the pyinstaller .zip or .exe
# main.py
if getattr( sys , 'frozen' , None ): # keyword 'frozen' is for setting basedir while in onefile mode in pyinstaller
basedir = sys._MEIPASS
else:
basedir = os.path.dirname( __file__ )
basedir = os.path.normpath( basedir )
os.environ[ 'REQUESTS_CA_BUNDLE' ] = os.path.join( basedir , 'cacert.pem' ) # required for pyinstaller to not use some default location for lib/requests
cacert_location = os.environ[ 'REQUESTS_CA_BUNDLE' ]
# downloader.py
cacert_location = os.environ[ 'REQUESTS_CA_BUNDLE' ] # required to avoid the pyinstaller with requests cacert bug
import requests
@staticmethod
def download_binary( url , local_file_path , original_modified_timestamp_milliseconds ):
"""https connection gets a binary stream in chunks and sets the finished download's modified timestamp"""
downloaded_bytes = 0
response = requests.get( url , verify = cacert_location , stream = True , timeout=30 ).raw # ssl enabled, streaming, raw mode, 30 second timeout
CHUNK = 1024 * 2048 # 1KB * 1024 = 1MB or 2MB
with open( local_file_path, 'wb' ) as file:
raw_data_chunk = response.read( CHUNK )
while raw_data_chunk:
file.write( raw_data_chunk )
raw_data_chunk = response.read( CHUNK )