【发布时间】:2017-11-29 00:05:31
【问题描述】:
我正在尝试使用 Python SDK 在我的 Stripe 帐户中复制一些订阅计划,以便我可以更新计划价格(计划是不可变的)。我可以成功列出所有计划,因此身份验证不是问题。:
import stripe
stripe.api_key = 'sk_test_...'
start_id = None
while True:
if start_id:
resp = stripe.Plan.list(starting_after=start_id)
else:
resp = stripe.Plan.list()
plans = resp['data']
if len(plans) == 0: break
start_id = plans[-1]['id']
for plan in plans:
new_amount = get_new_plan_amount(plan['id'], plan['name'])
new_plan = {
"id": "%s-v2" % plan["id"],
"name": "%s V2" % plan["name"],
"amount": new_amount,
"interval": plan["interval"],
"currency": plan["currency"],
}
if plan['interval_count']:
new_plan["interval_count"] = plan['interval_count']
if plan['metadata']:
new_plan["metadata"] = plan['metadata']
if plan['statement_descriptor']:
new_plan["statement_descriptor"] = plan['statement_descriptor']
stripe.Plan.create(new_plan) ### error
当我尝试更新计划时出现以下错误:
Stripe.error.AuthenticationError:提供的 API 密钥无效:“{'****': *'*********** ', '******** ': *'*****', '********_*****': *, '********': '', '******': *****, '**': *'*******-v2'}”。该键至少包含一个空格。请删除空格,然后重试。
我不明白。哪个字段包含空格?我检查了id 字段(它似乎在暗示),但该字段中没有空格。
我正在使用 Python 2.7 和 Stripe API 版本 2013-08-13。
【问题讨论】: