【发布时间】:2021-02-17 06:00:07
【问题描述】:
我看到一个与 Stripe 相关的奇怪错误,因为我无法使用我的实时 API 密钥创建源。
-
在我的应用程序中创建客户后,会在 Stripe 上创建一个客户(即实时 API 密钥正在工作)
-
当使用 test Stripe API 密钥时,我可以添加卡片并进行收费
-
当我在我的网站上使用我的 live API 密钥时,即使我将有效的源传递给函数,customer.sources.create() 调用也会失败。
stripe_customer_id = cus_IoiFADFAADFASDF (made up value for this post, but is a valid one in my environment that has been generated by Stripe) source = src_1ILfdf3asdfasdfasdfadsf (made up value for this post, but is a valid one in my environment that has been generated by Stripe) customer = stripe.Customer.retrieve(stripe_customer_id) stripe_card_response = customer.sources.create(source=source) #THIS IS THE LINE OF CODE THAT FAILS
我已确认我传递给这些函数的 stripe_customer_id 和源变量已填充。它们填充了从 Stripe 发送给我的值。
不幸的是,Stripe 不会返回任何可识别的错误。换句话说,当我在我的代码中处理以下异常时,只有最后一个被命中,这是一个通用的包罗万象。
except stripe.error.CardError as e:
except stripe.error.RateLimitError as e:
except stripe.error.InvalidRequestError as e:
except stripe.error.AuthenticationError as e:
except stripe.error.APIConnectionError as e:
except stripe.error.StripeError as e:
except Exception as e: #this is where the error falls as it doesn't relate to any of the others
500 错误返回以下内容
raise AttributeError(*err.args)
AttributeError: sources
感谢您的帮助!
【问题讨论】: