簡體   English   中英

輸出上的Python WSGI錯誤

[英]Python WSGI Error on Output

我的python已經很生銹了,因為我已經有一段時間沒有使用它了,並且遇到了一個我無法解決的問題。

python程序應接受網頁發送的表單數據,並向其返回一些JSON響應代碼。 一切正常,除了發送數據時:

def application(environ, start_response):
    """ Process the form data, spit out the reponse """

    # code here extracts the form 
    # data and the response code is 
    # stored in info

    # everything done, output now
    output(environ, start_response, info)


def output(environ, start_response, info):

    # debug
    print >> environ['wsgi.errors'], "BACK TO THE BROWSER"

    feedback = json.dumps(info)

    # debug
    print >> environ['wsgi.errors'], feedback

    status = "200 OK"
    headers = [('Content-Type', 'application/json; charset=UTF-8'), ('Content-Length', str(len(feedback)))]
    start_response(status, headers)
    return [feedback]

錯誤日志顯示:

...
[wsgi:error] ...返回瀏覽器

[wsgi:error] ... {“錯誤”:[1430360477881,1430233459050]}

[wsgi:error] ... mod_wsgi(pid = 1654):處理WSGI腳本'/ tmp / mod_wsgi-localhost:8000:0 / htdocs /'時發生異常。

[wsgi:error] ... TypeError:“ NoneType”對象不可迭代
...

好的,Python抱怨它期望可迭代的值是None。 但是Python在此函數中抱怨的是哪個可迭代的? (請注意,我沒有任何框架/模塊就直接使用mod_wsgi)。

您需要返回響應:

return output(environ, start_response, info)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM