self.status.split(' ',1)[0], self.bytes_sent 'NoneType' object has no attribute 'split'

當我們編寫wsgi時候報錯

錯誤內容

self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'

出錯代碼

def application(environ,start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/plain')]
    start_response(status, response_headers)
    return [u"hello"]

from wsgiref.simple_server import make_server
#導入系統的wsgi包
from webapp import application
#引入服務器的代碼

server =make_server('', 8080, application)
#實例化一個監聽8080端口的服務器
server.serve_forever()
#開始監聽http請求

解決方案

給返回內容加上.encode(‘utf8’)

return [u"hello".encode('utf8')]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章