Skip to main content
 首页 » 编程设计

python之未找到 cherrypy jsondecoder

2025年05月04日11JeffreyZhao

我试过这个例子:

import cherrypy 
 
class Root(object): 
    @cherrypy.expose 
    @cherrypy.tools.json_out() 
    def getrange(self, limit=4): 
        return list(range(int(limit))) 
 
cherrypy.quickstart(Root()) 

当我运行它时,我得到:

Traceback (most recent call last): 
  File "D:/Dev/BaronPOS/baronpos/Server/tester.py", line 1, in <module> 
    import cherrypy 
  File "C:\Python27\lib\site-packages\cherrypy\__init__.py", line 62, in <module> 
    from cherrypy._cpcompat import urljoin as _urljoin, urlencode as _urlencode 
  File "C:\Python27\lib\site-packages\cherrypy\_cpcompat.py", line 244, in <module> 
    json_decode = json.JSONDecoder().decode 
AttributeError: 'module' object has no attribute 'JSONDecoder' 

我完全不知道为什么。我已经检查了模块是否存在以及类是否存在。请帮忙!

请您参考如下方法:

好的,我明白了。

我之前使用的是 SimpleJSONRPCServer ( http://www.freenet.org.nz/dojo/pyjson/ ),但决定转向更灵活的 REST 兼容架构。

显然我留下了一个名为 json.py 的工件,它导致了这个......