【发布时间】:2020-11-17 12:42:53
【问题描述】:
当我发出 POST 请求时,我如何访问键的值(成功) 我已经尝试了以下
@app.route('/register', methods=['GET','POST'])
def vid():
if request.method == "POST":
firstname=request.form['firstname']
lastname=request.form['lastname']
email=request.form['email']
gender=request.form['gender']
phone=request.form['mobileno']
city=request.form['city']
dob=request.form['dob']
qualification=request.form['qualification']
marital=request.form['marital']
occupation=request.form['occupation']
logintype=request.form['logintype']
password=request.form['password']
redemptionmode=request.form['redemptionmode']
headers={'X-AUTH': 'GJTREWFRBN8675'}
inputs={'firstname': firstname , 'lastname': lastname,'email': email,'gender':
gender,'mobile':phone, 'city': city,
'dob': dob,'education':
occupation,'maritalstatus':marital,'occupation':occupation,'logintype':'local','password':password,
'redemptionmode': redemptionmode}
r = requests.post('https://api.imaginedreality.in/api/signup',headers=headers,data=inputs)
if r.success == "true":
#some operation#
else
#some operations#
'''
我得到一个错误“对象响应没有属性成功”但是有一个叫做成功锄头的键我可以访问它的值吗?
这是理想的反应
{"success": "true","data": { },"message": "Signup Success"}
【问题讨论】:
-
r.json()['success']顺便说一句,阅读文档可能是个好主意。
标签: python json api post response