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

时间:2019-11-19 08:00:26

标签: python stripe-payments

我正在使用我的测试API密钥在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密钥无效?为什么在测试模式下无法创建付款意向?

提前谢谢

1 个答案:

答案 0 :(得分:1)

如果第一个参数不是关键字参数,则它必须是API密钥。该函数的签名为(请参见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)