python - How to get valid json resp from Flask app with jsonapi version 1.0, "Content-type"="application/vnd.api+json" -


i have failed resp code below. have tried different "content-type", tried building json in different ways possible. please help.

@app.route('/api/v1/client', methods={'get', 'post'}) def client():  if request=='post':      req = request.get_data()      data = req.json      user_id = data["data"]["attributes"]["user_id"]      redirect_uri = data["data"]["attributes"]["_redirect_uris"]      default_scopes = data["data"]["attributes"]["_default_scopes"]       item = client(          client_id=gen_salt(40),          client_secret=gen_salt(55),           _redirect_uris=' '.join(redirect_uri),          _default_scopes=' '.join(default_scopes),          user_id=user_id,           allowed_grant_types=' '.join(['implicit', ]),          allowd_response_types=' '.join(['token', ])          )       db.session.add(item)      db.session.commit()       resp = {          "data":{              "attributes":{                  "client_id" : "client id",                  "client_secret" : "client_secret"              },          "jsonapi":{              "version" : "1.0"              },          "type":"client"          }      }       resp["data"]["attributes"]["client_id"] = item.client_id      resp["data"]["attributes"]["client_secret"]= item.client_secret      status = 200       return (jsonify(resp), status, {"content-type":"application/vnd.api+json"}) 

please, me! must doing entirely wrong. similar code working in function. error getting "valueerror: view function did not return response // werkzeug debugger".

first of all, if want check if request sent via post, should use if request.method == 'post': instead of if request == 'post':.

and if want json body of request, should use request.get_json().

the rest of work seems fine, i'd recommend read full flask documentation before doing something.


Comments

Popular posts from this blog

Qt QGraphicsScene is not accessable from QGraphicsView (on Qt 5.6.1) -

php - Cannot override Laravel Spark authentication with own implementation -

What is happening when Matlab is starting a "parallel pool"? -