python3 AttributeError: 'NoneType' object has no attribute 'split'

时间:2023-03-08 21:57:35
 from wsgiref.simple_server import make_server

 def RunServer(environ, start_response):
start_response('200 ok',[('Content-Type','text/html')])
return '<h1>Hello world</h1>' if __name__ == '__main__':
httpd = make_server('127.0.0.1',9000,RunServer)
print('servering HTTP on port 9000')
httpd.serve_forever()

Code

运行时报错:

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

解决办法如下:

return ['<h1>Hello world</h1>'.encode('utf-8'),]