Python 3.x 参数必须是字节实例WSGI Python3

Python 3.x 参数必须是字节实例WSGI Python3,python-3.x,wsgi,pysimplesoap,wsgiref,Python 3.x,Wsgi,Pysimplesoap,Wsgiref,我在Python3中有一个带有pysimplesoap的soap服务器。我不知道,因为我有下一个错误 代码 from wsgiref.simple_server import make_server application = WSGISOAPHandler(dispatcher) wsgid = make_server('', 8008, application) wsgid.serve_forever() 错误 Traceback (most recent c

我在Python3中有一个带有pysimplesoap的soap服务器。我不知道,因为我有下一个错误

代码

   from wsgiref.simple_server import make_server
    application = WSGISOAPHandler(dispatcher)
    wsgid = make_server('', 8008, application)
    wsgid.serve_forever()
错误

Traceback (most recent call last):
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 138, in run
    self.finish_response()
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 180, in finish_response
    self.write(data)
  File "/usr/lib/python3.4/wsgiref/handlers.py", line 266, in write
    "write() argument must be a bytes instance"
AssertionError: write() argument must be a bytes instance

in.py第180行


self.write(data.encode())而不是self.write(data)

这都是因为WSGI是为Python2设计的,所以在python3中使用它可能会遇到一些麻烦。 如果您不想像第一个答案中那样更改库的行为,解决方法是对所有文本数据进行编码,如:

def application(environ,start_response):
    response_body = 'Hello World'
    return [response_body.encode()]

Wsgi框架是围绕Python2构建的。因此,如果您的程序中有不包含Python 3依赖项的内容,请使用Python 2运行应用程序。

解释错误的原因和原因?
def application(environ,start_response):
    response_body = 'Hello World'
    return [response_body.encode()]