AttributeError: 'Request' object has no attribute 'get'
16,386
Just as i posted this question, i found the answer:
I needed to change
'Title': request.get('Title', ""),
to
'Title': request.json.get('Title', ""),
Comments
-
human almost 2 years
When i make a POST request to my server, i get a 500 ERROR with comment:
AttributeError: 'Request' object has no attribute 'get'
This is my server:
@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
here is also my entries array:
entries = [ { 'id': 1, 'Title': 'baradum', 'Description': 'desc 1', 'Info': 'info1', }, { 'id': 2, 'Title': 'jasd', 'Description': 'desc 2', 'Info': 'info 2', } ]
What causes the problem?
-
Some programmer dude almost 10 yearsAre you sure that is the code you have, with the indentation as shown in your question?
-
Captain Sparrow about 8 yearsThis helped me. stackoverflow.com/questions/10320307/…
-