【发布时间】:2014-03-10 06:33:45
【问题描述】:
我有一个名为succeed 的python 包装器方法,如下所示:
def succeed(handler, data):
"""Send the given |data| dict as a JSON response in |handler.response|."""
set_headers(handler)
handler.response.write(json.dumps(data))
我正在尝试将 Stripe API 调用的结果传递给使用此方法从信用卡扣款的另一项服务。这是另一个类中的方法调用:
succeed(self, dict(success=True, charge_id=charge.id, response=charge))
当我这样做时,我收到“费用不是 JSON 可序列化”错误。如何使用此代码将所有费用 ID 响应作为 JSON 传递?以下是完整回复:
TypeError: <Charge charge id=ch_103Tsv2kD9PLZlzDG5ce7TE1 at 0x113003b50> JSON: {
"amount": 3500,
"amount_refunded": 0,
"balance_transaction": "xxxxxx",
"captured": true,
"card": {
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"country": "US",
"customer": null,
"cvc_check": "pass",
"exp_month": 5,
"exp_year": 2015,
"fingerprint": "xxxxxxxxxxxxxx",
"last4": "4242",
"name": "stackoverflow@example.com",
"object": "card",
"type": "Visa"
},
"created": 1392181282,
"currency": "usd",
"customer": null,
"description": "X0G0 FEOMSI NA",
"dispute": null,
"failure_code": null,
"failure_message": null,
"invoice": null,
"livemode": false,
"metadata": {
"email": "stackoverflow@exmple.com"
},
"object": "charge",
"paid": true,
"refunded": false,
"refunds": []
}
【问题讨论】:
标签: python json stripe-payments