如何从 Python POST 请求中获取 JSON 数据 [英] How to get JSON data from a Python POST request
本文介绍了如何从 Python POST 请求中获取 JSON 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我尝试获取该 POST 请求命令的答案时,它只返回第一个参数:
Whenever I try to get the answer of that POST request command, it returns only the first argument:
s = requests.post('https://martindarc59.typeform.com/app/form/result/token/AdHdvM/default')
print (s.text)
它应该输出这个:在此处输入图片描述
但是,我只得到令牌值而不是 landed_at
,我需要在我的代码中同时在表单末尾提交它们.
However, I only get the token value and not the landed_at
, I need both in my code to submit them at the end of my form.
谢谢!
推荐答案
您需要发送Accept":application/json"
标头,即:
You need to send the "Accept": "application/json"
header, i.e.:
import requests
u = "https://martindarc59.typeform.com/app/form/result/token/AdHdvM/default"
j = requests.post(u, headers={"Accept": "application/json"}).json()
# {'token': '20903331626f396431746f397777693832713331626f39643136747572367978706434313339363936363463366336363533373434333536343134353337366237613339343233303664373236613737353935613431363436393336343833313335333833383332333733393336333333373633653233363637346132653432343938383963326537663165326535633262373837326336613437343539666638653932613131393266386236393635626131353838323739363337', 'landed_at': '1588279637'}
这篇关于如何从 Python POST 请求中获取 JSON 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文