我能够很好地接收webhook,但是当我试图添加代码来读取数据时,它返回一个错误。我是不是分析错了
@require_POST
@csrf_exempt
def webhook(request):
print("webhook kaldt")
event_json = json.loads(request.body)
status = event_json['status']
print(status)
return HttpResponse(status=200)
如果我删除status
变量和打印行,那么一切都会正常。只要我试着分析数据
来自事件json的数据如下所示
{"created": 1326853478, "livemode": false, "id": "charge.succeeded_00000000000000", "type": "charge.succeeded", "object": "event", "request": null, "pending_webhooks": 1, "api_version": "2019-03-14", "data": {"object": {"id": "ch_00000000000000", "object": "charge", "amount": 100, "amount_refunded": 0, "application": null, "application_fee": null, "application_fee_amount": null, "balance_transaction": "txn_00000000000000", "billing_details": {"address": {"city": null, "country": "DK", "line1": null, "line2": null, "postal_code": null, "state": null}, "email": null, "name": "qwewqwq", "phone": null}, "captured": false, "created": 1553170537, "currency": "dkk", "customer": null, "description": "My First Test Charge (created for API docs)", "destination": null, "dispute": null, "failure_code": null, "failure_message": null, "fraud_details": {}, "invoice": null, "livemode": false, "metadata": {}, "on_behalf_of": null, "order": null, "outcome": null, "paid": true, "payment_intent": null, "payment_method_details": {"card": {"brand": "visa", "checks": {"address_line1_check": null, "address_postal_code_check": null, "cvc_check": "pass"}, "country": "US", "exp_month": 1, "exp_year": 2022, "fingerprint": "JKbTj7sZqbPMQJ9p", "funding": "credit", "last4": "4242", "three_d_secure": null, "wallet": null}, "type": "card"}, "receipt_email": null, "receipt_number": null, "receipt_url": "https://pay.stripe.com/receipts/acct_1E4YZiB2MQ8LEk6k/ch_1EGPo5B2MQ8LEk6k47xo3CcZ/rcpt_EjtbkjCrHE8bfSS0Xxa5iW3UBNjqK7C", "refunded": false, "refunds": {"object": "list", "data": [], "has_more": false, "total_count": 0, "url": "/v1/charges/ch_1EGPo5B2MQ8LEk6k47xo3CcZ/refunds"}, "review": null, "shipping": null, "source": {"id": "card_00000000000000", "object": "card", "address_city": null, "address_country": "DK", "address_line1": null, "address_line1_check": null, "address_line2": null, "address_state": null, "address_zip": null, "address_zip_check": null, "brand": "Visa", "country": "US", "customer": "cus_00000000000000", "cvc_check": "pass", "dynamic_last4": null, "exp_month": 1, "exp_year": 2022, "fingerprint": "JKbTj7sZqbPMQJ9p", "funding": "credit", "last4": "4242", "metadata": {}, "name": "qwewqwq", "tokenization_method": null}, "source_transfer": null, "statement_descriptor": null, "status": "succeeded", "transfer_data": null, "transfer_group": null}}}
如果您美化json,您将看到根对象中没有“status”属性
你可以试试
格式化的json
相关问题 更多 >
编程相关推荐