首页 > 解决方案 > 烧瓶 api 没有返回 xml

问题描述

我不能让我的 Flask API 返回 XML。

我在错误日志中没有收到任何错误,但这是来自服务器日志:

2020-06-10 21:14:01 [Errno 2] No such file or directory: '<bound method Response.json of <Response [200]>>'
2020-06-10 21:14:01 [Errno 2] No such file or directory: '<bound method Response.json of <Response [200]>>'
2020-06-10 21:14:02 DAMN ! worker 1 (pid: 2) died :( trying respawn ...
2020-06-10 21:14:02 Respawned uWSGI worker 1 (new pid: 13)
2020-06-10 21:14:02 spawned 2 offload threads for uWSGI worker 1

从 pythonanywhere 我得到这个消息:

出问题了 :-(

        <p>
            This website is hosted by PythonAnywhere, an online hosting
            environment. Something went wrong while trying to load it;
            please try again later.
        </p>

        <div class="for-site-owner">
            <h2>Debugging tips</h2>
            <p>
                If this is your PythonAnywhere-hosted site, and you just reloaded
                it, then the problem might simply be that it hasn&#39;t loaded up yet.
                Try refreshing this page and see if this message disappears.
            </p>

            <p>
                If you keep getting this message, you should check your site&#39;s
                server and error logs for any messages &mdash; you can view them
                from the Web tab inside PythonAnywhere.
            </p>

            <p>
                If there&#39;s nothing in the logs, and you&#39;re sure your site is OK,
                then it might be a problem on our side. Drop us a line at
                support@pythonanywhere.com, in the forums, or using the &quot;Send
                feedback&quot; link on the site, quoting the error code below.
            </p>
        </div>

        <p>
            Error code: 502-backend

这是我的代码:

r = requests.request("GET", url, headers=headers)

# get the xml from a json string

if r.status_code == 200:
    js_data = str(r.json)
    xml_data = readfromjson(js_data)
    return json2xml.Json2xml(xml_data).to_xml()

我可以返回 js_data 没问题

BR克雷斯顿

标签: pythonxmlflask

解决方案


推荐阅读