How can I return json in flask python from another url to browser?

I want to use a jar to return JSON to a brower with or without simplejson (with appropriate headers), here is what I have so far used for my flash application:

@app.route('/') def hello_world(): QUERY_URL="http://someappserver:9902/myjsonservlet" result = simplejson.load(urllib.urlopen(QUERY_URL)) return result; 

Assuming JSON output is returned:

 {"myapplication":{"system_memory":21026160640.0,"percent_memory":0.34, "total_queue_memory":4744,"consumers":1,"messages_unacknowledged":0, "total_messages":0,"connections":1} 

When I visit the page http://localhost:5000 , I get an Internal Server Error . What should I do with the β€œresult” to display it accordingly? Or can I say that he came back with json headers?

When I add a print statement to print the result, I see JSON, but in the browser it gives me Internal Server Error .

+6
source share
1 answer
 import requests r = requests.get(QUERY_URL) return r.json #normal return return jsonify(username=g.user.username, email=g.user.email, id=g.user.id) 

jsonify is available in the bulb. Here are the docs

+10
source

Source: https://habr.com/ru/post/922391/


All Articles