1

I built a Python Package to handle API requests (which uses the requests library) and the code written using the package built gets executed either as a standalone script or sometimes gets packaged as an executable for others to use, with PyInstaller:

PyInstaller -F api_interaction_script.py

Executing the scripts with python api_interaction_script.py doesn't cause any issues and it's been working really well. So, I started migrating all my PyInstaller packaged executables to start using the package I built and when I try to execute the executable, it runs into the following error:

Traceback (most recent call last):
  File "update_settings.py", line 14, in <module>
  File "custom_handler.py", line 51, in __init__
  File "custom_handler.py", line 178, in get_application_details
  File "custom_handler.py", line 58, in post_request
  File "requests\api.py", line 117, in post
  File "requests\api.py", line 61, in request
  File "requests\sessions.py", line 542, in request
  File "requests\sessions.py", line 655, in send
  File "requests\adapters.py", line 416, in send
  File "requests\adapters.py", line 227, in cert_verify
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\RAJEND~1.KOD\AppData\Local\Temp\_MEI124482\certifi\cacert.pem
[24980] Failed to execute script 'update_settings' due to unhandled exception!

I kept the Temp folder open to see whether a cacert.pem is being generated at all to ensure that this isn't something related to accessibility but I don't see the folder certifi being created at all.

Could this be an issue with the requests library not being a direct import into the script being packaged or could it be something else; Because, when the package's(Custom Python Package) functionality is built into the script packaged(PyInstaller Executable), it works just fine.

PS: This may not have anything to do with the problem but I did upgrade to Python 3.10, not that I tested this with older versions.

Edit

I was able to resolve it by doing clean uninstall of Python 3.10 and installing Python 3.9.7 (Most up to date non 3.10 version there is, as of 11/02/2021). Strange, but hey, requirement fulfilled I suppose.

I found this post before posting this, it's quite old and the cause doesn't seem to be the same. Because, directly importing requests into the script that is being packaged is not causing this problem. I guess the solution that worked for me, no longer makes it a duplicate of the other post. I would appreciate anyone sharing an explanation!

0 Answers0