gpt4 book ai didi

python-3.x - "AssertionError: write() argument must be a bytes instance"运行 WSGI SOAPHandler 时

转载 作者:行者123 更新时间:2023-12-03 23:31:30 25 4
gpt4 key购买 nike

我在 Python 3 中有一个带有 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

最佳答案

这都是因为 WSGI 是为 Python 2 制作的,所以你在 Python 3 中使用它可能会遇到一些麻烦。如果你不想像第一个答案那样改变库的行为,解决方法是 encode() 所有文本数据,如:

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

关于python-3.x - "AssertionError: write() argument must be a bytes instance"运行 WSGI SOAPHandler 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35886782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com