Reputation: 2295
I'm creating a payment intent in Stripe, with my test API key. My python code looks like:
stripe.api_key = "sk_test_*"
response = stripe.PaymentIntent.create({'amount': amount,'currency': currency,'description': description, 'customer': customer})
However, I'm getting the following error:
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'}
What is going on? Why is my API key not valid? Why do I couldn't create a payment intent in test mode?
Thank you in advance
Upvotes: 1
Views: 1289
Reputation: 17711
If the first parameter is not a keyword argument, it must be the API key. The function's signature is (see stripe/api_resources/creatable-api_resource.py
):
stripe.PaymentIntent.create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
)
So you should omit the braces, because the dictionary is given as first parameter to api_key
:
response = stripe.PaymentIntent.create(
'amount': amount, 'currency': currency,
'description': description, 'customer': customer)
Upvotes: 1