Skip to Content
Menú
This question has been flagged
2 Respostes
13876 Vistes

I have web controller working with external system.

@http.route('/path/'auth='none'type="json"methods=['POST'], csrf=Falsecors='*')
def index(self, **kw):
    data = json.loads(request.httprequest.data) # I need raw data
return data

If I have type="json" I can get raw data from request without "parameters" via request.httprequest.data, but when I try to send response, I get

{
  "jsonrpc": "2.0",
"id": null,
"result": {
"test": "data"
} }

But I need to receive just

{  
"test": "data",
}

If I change type to "http" I can create correct response like this

headers = {"Content-Type""application/json"}
return Response(json.dumps(body), headers=headers)

But I have an error when I try to do a request

Function declared as capable of handling request of type 'http' but called with a request of type 'json'
It's external system, I can't change it. How to create a correct response without "result"?

Avatar
Descartar
Best Answer

Why don't you simply return result from your json from your route/controller?

Ex:

return data.get('result', {})


Avatar
Descartar
Best Answer

i did it this way 

from werkzeug.wrappers import Request, Response

headers = {'Content-Type': 'application/json'}
body = data

return Response(json.dumps(body), headers=headers)


Avatar
Descartar