Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 樱桃糖休息>;TypeError:块不是bytes类型_Python_Python 3.x_Cherrypy - Fatal编程技术网

Python 樱桃糖休息>;TypeError:块不是bytes类型

Python 樱桃糖休息>;TypeError:块不是bytes类型,python,python-3.x,cherrypy,Python,Python 3.x,Cherrypy,我无法查看JSON数据。视图不起作用 500内部服务器错误 服务器遇到意外情况,无法满足请求 Traceback (most recent call last): File "C:\Python3\lib\site-packages\cherrypy\_cprequest.py", line 675, in respond response.finalize() File "C:\Python3\lib\site-packages\cherrypy\_cprequest.py",

我无法查看JSON数据。视图不起作用

500内部服务器错误

服务器遇到意外情况,无法满足请求

Traceback (most recent call last):
  File "C:\Python3\lib\site-packages\cherrypy\_cprequest.py", line 675, in respond
    response.finalize()
  File "C:\Python3\lib\site-packages\cherrypy\_cprequest.py", line 947, in finalize
    content = self.collapse_body()
  File "C:\Python3\lib\site-packages\cherrypy\_cprequest.py", line 911, in collapse_body
    repr(chunk))
TypeError: Chunk {'__type__': 'Anchor', 'code': 'AN2', 'fwver': '0.8', 'host': '10.10.10.105', 'hwver': '0.10', 'idanchor': '2b590a73-e7af-47a1-bee5-dc8dd854e86a', 'locgeog': '0101000020E6100000A541A070CA092D40C055CEC46F074940', 'name': 'V rohu vpravo od dveří', 'port': 12344, 'rtlsaddress': 'DECA013010000BD6'} is not of type 'bytes'

我认为CherryPy对这个错误不是很友好,但基本上处理程序应该返回
字节
而不是字典。为此,您需要使用
@cherrypy.tools.json\u out()
来修饰该方法


有关详细信息:

如果isinstance(self.body,text_或_bytes),则输入必须为str或bytes:对于self.body中的chunk,返回self.body newbody=[]如果self.PY3而不是isinstance(chunk,bytes):引发类型错误(“chunk%s不是'bytes'类型。”%repr(chunk))newbody.append(chunk)newbody=ntob(“”).join(newbody)