如何将从另一个url获取的flask python中的JSON返回给浏览器?

Rol*_*ndo 6 python flask

我想使用flask将JSON返回给浏览器,有或没有simplejson(带有适当的标题)这是我到目前为止我的烧瓶应用程序:

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

假设返回的JSON输出是:

{"myapplication":{"system_memory":21026160640.0,"percent_memory":0.34,
"total_queue_memory":4744,"consumers":1,"messages_unacknowledged":0,
"total_messages":0,"connections":1}
Run Code Online (Sandbox Code Playgroud)

当我访问该页面http://localhost:5000时,我得到了一个Internal Server Error.我必须对"结果"做些什么才能让它正确显示?或者有什么方法我可以告诉它返回json标题?

当我添加一个print语句来打印结果时,我可以看到JSON,但是在浏览器中它给了我一个Internal Server Error.

Kra*_*mar 10

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)
Run Code Online (Sandbox Code Playgroud)

jsonify可用于烧瓶.这是文档