Python启动WSGI,make_server报错

今天写了一个简单的python web server,启动后访问浏览器报了一个错误,如下:

Serving HTTP on port 8088...
127.0.0.1 - - [29/May/2019 16:08:29] "GET / HTTP/1.1" 200 0
Traceback (most recent call last):
File "D:\Python\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "D:\Python\lib\wsgiref\handlers.py", line 181, in finish_response
self.write(data)
File "D:\Python\lib\wsgiref\handlers.py", line 267, in write
"write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

根据报错信息提示最终可得知write()接收的参数不是一个bytes类型。
最终定位报错的位置在handlers.py finish_response() 这个函数中self.write(data),在self.write(data)上添加代码data=data.encode(),重启服务即可

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注