如何从json响应中获取并打印发票URL和商人名称?在Python中
path2
响应
import requests
import csv
from google.colab import files
url = "https://api.vdit.co/v2/invoices"
payload = "{\n\t\"external_id\": \"invoice-1597479693\",\n\t\"amount\": 3800000,\n\t\"payer_email\": \"customer@domain.com\",\n\t\"description\": \"Invoice Demo #1234\"\n}"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Basic sfdfsdfsdfdsfds==',
'Cookie': 'visid_incap_2182539=9txMzsXTSfuzBolYeHI2Ui6hLl4AAAAAQUIPAAAAAABantpi5VKWQTh30yiNhG8y; nlbi_2182539=H15dNsiPqheQ/JGAjjCKbQAAAAAuILnoaVKZa2DtKg9G+o7E; incap_ses_1130_2182539=pdnQReH84gIVq2yWKJGuDz2aN18AAAAABIuVf37dWMch3rIN+1PZJg=='
}
response = requests.request("POST", url, headers=headers, data = payload)
print(response.text)
如何从json响应中获取并打印发票网址和商人名称?在Python中
我希望结果是这样,请指导我
发票网址: “ https://invoice-staging.vdit.co/web/invoices/5f38a9e14b73f4203a87465b” vendor_name:PT ABC ASIA TENGGARA
预先感谢
答案 0 :(得分:1)
类似的东西应该起作用
resp = response.json()
invoice_url = resp['invoice_url']
merchant_name = resp['merchant_name']
print(invoice_url, marchant_name)