gpt4 book ai didi

python - 在 Stripe 中创建付款意向时出错

转载 作者:行者123 更新时间:2023-12-01 06:52:37 25 4
gpt4 key购买 nike

我正在使用我的测试 API key 在 Stripe 中创建付款意图。我的 python 代码如下所示:

stripe.api_key = "sk_test_*"
response = stripe.PaymentIntent.create({'amount': amount,'currency': currency,'description': description, 'customer': customer})

但是,我收到以下错误:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.7/site- packages/stripe/api_resources/abstract/createable_api_resource.py", line 22, in create
response, api_key = requestor.request("post", url, params, headers)
File "/usr/local/lib/python3.7/site-packages/stripe/api_requestor.py", line 121, in request
resp = self.interpret_response(rbody, rcode, rheaders)
File "/usr/local/lib/python3.7/site-packages/stripe/api_requestor.py", line 372, in interpret_response
self.handle_error_response(rbody, rcode, resp.data, rheaders)
File "/usr/local/lib/python3.7/site-packages/stripe/api_requestor.py", line 151, in handle_error_response
raise err
stripe.error.AuthenticationError: Invalid API Key provided: {'amount******************************************************nt'}

这是怎么回事?为什么我的 API key 无效?为什么我无法在测试模式下创建付款意图?

提前谢谢

最佳答案

如果第一个参数不是关键字参数,则它必须是 API key 。该函数的签名是(请参阅stripe/api_resources/creatable-api_resource.py):

stripe.PaymentIntent.create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
)

因此您应该省略大括号,因为字典作为 api_key 的第一个参数给出:

response = stripe.PaymentIntent.create(
'amount': amount, 'currency': currency,
'description': description, 'customer': customer)

关于python - 在 Stripe 中创建付款意向时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58929161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com