AttributeError:“请求"对象没有属性“获取" [英] AttributeError: 'Request' object has no attribute 'get'
本文介绍了AttributeError:“请求"对象没有属性“获取"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我向服务器发出POST请求时,出现500错误并带有注释:
When i make a POST request to my server, i get a 500 ERROR with comment:
AttributeError: 'Request' object has no attribute 'get'
这是我的服务器:
@app.route('/api/entries', methods = ['POST'])
def create_entry():
if not request.json:
abort(400)
entry = {
'id': entries[-1]['id'] + 1,
'Title': request.get('Title', ""),
'Description': request.get('Description', ""),
'Info': request.get('Info', "")
}
entries.append(entry)
return jsonify( { 'entry': entry } ), 201
这也是我的条目数组:
entries = [
{
'id': 1,
'Title': 'baradum',
'Description': 'desc 1',
'Info': 'info1',
},
{
'id': 2,
'Title': 'jasd',
'Description': 'desc 2',
'Info': 'info 2',
}
]
是什么原因引起的问题?
What causes the problem?
推荐答案
就像我发布这个问题一样,我找到了答案:
Just as i posted this question, i found the answer:
我需要改变
'Title': request.get('Title', ""),
到
'Title': request.json.get('Title', ""),
这篇关于AttributeError:“请求"对象没有属性“获取"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文