1. 程式人生 > 其它 >測試uwsgi,報錯Unhandled object from iterator

測試uwsgi,報錯Unhandled object from iterator

技術標籤:Python

pip install uwsgi
uwsgi --version    # 檢視 uwsgi 版本

測試 uwsgi 是否正常:

新建 test.py 檔案,內容如下:

def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"

然後在終端執行:

uwsgi --http :8001 --wsgi-file test.py

在瀏覽器內輸入:http://127.0.0.1:8001,檢視是否有"Hello World"輸出

訪問地址,後臺報錯:

解決:對於python3則應當注意要指明編碼,否則uwsgi不會發送網頁內容

​def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    test = 'hello world'
    return test.encode("utf-8")