2017-11-28 24 views
1

プランの価格を更新できるように、Python SDKを使用してStripeアカウントでいくつかのサブスクリプションプランを複製しようとしています。私は正常にすべてのプランを一覧表示することができますので、認証は問題ではありません。:Python Stripe SDK認証エラー(キーに少なくとも1つの空白が含まれています)

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: Invalid API Key provided: "{'****': *'*********** ', '********': *'*****', '********_*****': *, '********': '', '******': *****, '**': *'*******-v2'}". This key contains at least one space. Please delete the spaces and try again.

私はそれを得ることはありませんが。スペースを含むフィールドはどれですか?私はidフィールド(これは示唆しているようです)をチェックしましたが、そのフィールドにスペースはありません。

私はStripe APIのPython 2.7および2013-08-13を使用しています。

答えて

1

あなたが計画を作成するときに、あなたのパラメータを含む辞書を解凍する必要があります。

stripe.Plan.create(**new_plan) 

また、あなたはページネーションのパラメータを自分で管理する必要はありません。 Pythonライブラリは、auto-paginationを使用してそれを行うことができます:

+0

あなたが解凍すると、その関数がJSON文字列をパラメータとして期待しているのでしょうか? – RTF

+0

'stripe.Plan.create()'メソッドはディクショナリではなくキーワード引数を要求しているので、引数リストを展開する必要があります:https://docs.python.org/dev/tutorial/controlflow.html#unpacking-引数リスト。 – Ywain