Pyinstaller 和 API 密钥

问题描述 投票:0回答:0

我最近做了一个脚本,是一个单一的功能

fill()
.

脚本在Pycharm中运行没有问题

我开始尝试使用 pyinstaller,下面的代码效果很好:

pyinstaller --onefile main.py
:它创建了一个完美运行的 .exe。

我添加了一个功能

chargebee.configure(site='site-address', api_key='api_key')
subscription_key = "subscription_key"

def check_subscription(subscription_key):
    try:
        subscription = chargebee.Subscription.retrieve(subscription_key)
        if subscription.subscription.status == "active":
            fill()
        else:
            print("Subscription is either not active or is having an issue, please check to make sure your subscription is valid if you continue having issues")
            return False
    except:
        print("Subscription is either not active or is having an issue, please check to make sure your subscription is valid if you continue having issues")
        return False

if __name__ == '__main__':
    print("Starting:")
    check_subscription(subscription_key)

这在 Pycharm 中运行完美,但是当我运行 pyinstaller --onefile main.py 并将其转换为 .exe.

我运行 .exe 并返回:订阅未激活或有问题,如果您继续遇到问题,请检查以确保您的订阅有效(对于我检查的上下文,这是来自 try/except不是来自 if 语句。这意味着

subscription = chargebee.Subscription.retrieve(subscription_key)

有一些错误

有什么想法吗?

是因为 API 密钥是硬编码的吗?

python pycharm pyinstaller
© www.soinside.com 2019 - 2024. All rights reserved.