1

I have been using the stripe python module for my program. When I run my file directly as a .py file it runs without any issues, as soon as I convert it to a exe with pyarmor, which uses pyinstaller, I get a TLS CA certificate missing error.

ERROR:

Unexpected error communicating with Stripe. It looks like there's
probably a configuration issue locally.  If this problem persists, let
us know at support@stripe.com.

(Network error: A OSError was raised with error message Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\ADMINI~1\AppData\Local\Temp\2\_MEI119082\stripe\data\ca-certificates.crt)

Can anyone help?

The DEV
  • 53
  • 1
  • 8

3 Answers3

1

I've been dealing with this myself, have you tried a solution like this. It deals with a permissions issue of the executable not allowing the pyfile inside of the exe to directly reference Path Variables. The workaround being that it reads them into a special Path variable that can interface with the environment after it's an exe.

The best solutions looked something like this:

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)

    return os.path.join(os.path.abspath("."), relative_path)

Original Post of this function

Could be a completely different issue with pyinstaller though I think it's the same one I'm having.

0

I had a similar issue with Nuitka. I fixed it by adding a function

def set_certificate(certificate_path: str) -> None:
    stripe.ca_bundle_path = certificate_path

add calling it at the beginning of my program:

def main():
    set_certificate("stripe/data/ca-certificates.crt")
    ...

where stripe/data/ca-certificates.crt is the relative path of my cert file.

PhunkyBob
  • 16
  • 4
0

I had the exact same error issue with stripe and PyInstaller as OP. There were no great answers anywhere but I finally got it working. It involves downloading the ca-certificates.crt file from the stripe-python github here:

https://github.com/stripe/stripe-python/blob/master/stripe/data/ca-certificates.crt

I then put the file in the same folder as my script and added this code:

import os
import stripe

current_directory = os.getcwd()
ca_cert_path = os.path.join(current_directory, 'ca-certificates.crt')

stripe.ca_bundle_path = ca_cert_path

Then you can build your executable using PyInstaller like you normally would.

Unfortunately you will have to deliver the crt file with the executable file. I am sure there is a better way but I have not yet found it and this one works so I am going with it for now.

eekbah
  • 1