I'm trying to create a python app that will check for newer versions of itself on GitHub. The way it checks is by finding a txt file in the repository that has the latest version number on it. My code works just fine and does what I want it to when running it with PyCharm but when I use cx_Freeze and run the exe it has trouble.
I started by using requests which worked fine until freezing, then I switched to urllib3 which had the same result. I tried simply pinging google which worked after freezing so I know it's not an issue with connecting to the internet.
from urllib3 import PoolManager
version_url = "https://raw.githubusercontent.com/redscientific/CompanionApp/master/Version.txt"
def get_data():
mgr = PoolManager()
r = mgr.request("GET", version_url)
...then I parse the data etc.
Before I freeze it I get the results I need but after I freeze it it seems to have trouble at r = mgr.request("GET", version_url)
I don't know what error it's having because I don't know how to get errors back from a .exe other than printing lines to a file but it won't get to any lines after mgr.request()
so I can't output anything after the error happens.
I guess my question is how do I get it to work after I freeze it?
The error it spits out is as follows:
urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.
Apparently cx_Freeze does not automatically add a couple of required .dll
files. A fix I have found upon more googling is described here.
Try to run your exe from a cmd
prompt or terminal, you should be able to see the error message in the terminal window then.
If you still prefer to print the exception to a file from within the application, you can use a try
... except
block to catch the exception and use then traceback.print_exc()
to print the exception, see How to print the full traceback without halting the program?
Assuming the line r = mgr.request("GET", version_url)
causes the exception, replace it by:
import traceback
try:
r = mgr.request("GET", version_url)
except Exception:
with open('logfile.txt', 'w') as f:
traceback.print_exc(file=f)