Cherrypy REST> TypeError: Chunk is not of type bytes

Cherrypy REST> TypeError: Chunk is not of type bytes

我在查看 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 对那个错误不是很友好,但基本上处理程序应该 return bytes 而不是字典。为此,您需要使用 @cherrypy.tools.json_out().

修饰方法

更多信息:http://docs.cherrypy.org/en/latest/basics.html?highlight=json#encoding-response