Stripe TLS CA证书与pyinstaller问题

huangapple go评论90阅读模式
英文:

Stripe TLS CA certificate Issue with pyinstaller

问题

抱歉,我无法理解你的请求。 你想要我翻译整个文本吗? 还是只需要翻译其中的代码部分? 请提供更多明确的指示。

英文:

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:

  1. Unexpected error communicating with Stripe. It looks like there's
  2. probably a configuration issue locally. If this problem persists, let
  3. us know at support@stripe.com.
  4. (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\_MEI119082\stripe\data\ca-certificates.crt)

Can anyone help?

答案1

得分: 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:

  1. def resource_path(relative_path):
  2. """ Get absolute path to resource, works for dev and for PyInstaller """
  3. if hasattr(sys, '_MEIPASS'):
  4. return os.path.join(sys._MEIPASS, relative_path)
  5. 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.

英文:

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:

  1. def resource_path(relative_path):
  2. """ Get absolute path to resource, works for dev and for PyInstaller """
  3. if hasattr(sys, '_MEIPASS'):
  4. return os.path.join(sys._MEIPASS, relative_path)
  5. 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.

答案2

得分: 0

我在使用Nuitka时遇到了类似的问题。
我通过添加一个函数来解决它:

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

在我的程序开头调用它:

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

其中 stripe/data/ca-certificates.crt 是我的证书文件的相对路径。

英文:

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

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

add calling it at the beginning of my program:

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

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

答案3

得分: 0

我遇到了与 stripe 和 PyInstaller 一样的错误问题,与 OP 一样。任何地方都没有找到很好的答案,但最终我解决了它。它涉及从 stripe-python 的 GitHub 上下载 ca-certificates.crt 文件:

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

然后,我将文件放在与我的脚本相同的文件夹中,并添加了这段代码:

  1. import os
  2. import stripe
  3. current_directory = os.getcwd()
  4. ca_cert_path = os.path.join(current_directory, 'ca-certificates.crt')
  5. stripe.ca_bundle_path = ca_cert_path

然后,您可以像通常一样使用 PyInstaller 构建可执行文件。

不幸的是,您将不得不将 crt 文件与可执行文件一起交付。我确信有更好的方法,但我尚未找到它,所以暂时使用这种方法。

英文:

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:

  1. import os
  2. import stripe
  3. current_directory = os.getcwd()
  4. ca_cert_path = os.path.join(current_directory, 'ca-certificates.crt')
  5. 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.

huangapple
  • 本文由 发表于 2023年2月6日 05:18:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355580.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定