Python 未找到cherrypy jsondecoder

Python 未找到cherrypy jsondecoder,python,cherrypy,Python,Cherrypy,我试过这个例子: 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):

我试过这个例子:

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'
回溯(最近一次呼叫最后一次):
文件“D:/Dev/BaronPOS/BaronPOS/Server/tester.py”,第1行,在
进口樱桃
文件“C:\Python27\lib\site packages\cherrypy\\uuuuu init\uuuuuuu.py”,第62行,在
从cherrypy.\u cpcompat导入urljoin作为\u urljoin,urlencode作为\u urlencode
文件“C:\Python27\lib\site packages\cherrypy\\u cpcompat.py”,第244行,在
json_decode=json.JSONDecoder().decode
AttributeError:“模块”对象没有属性“JSONDecoder”
我完全不知道为什么。我已经检查了模块是否存在,类和两者是否都存在。请帮忙

好吧,我想出来了

我以前使用的是SimpleJSONRPCServer(),但决定转向更灵活的REST兼容体系结构


很明显,我留下了一个名为json.py的工件,这导致了…

它是版本2.7.1,cherrypy是从cherrypy-3.2.0-py2.win32.exe安装的。是否安装了simplejson?尝试“import simplejson”听起来您的json模块可能已损坏。您可以尝试“import json/print json.JSONDecoder”吗?否给出了相同的错误:回溯(最近一次调用):文件“D:/Dev/BaronPOS/BaronPOS/Server/tester.py”,在print json.JSONDecoder AttributeError中的第2行:“module”对象没有属性“JSONDecoder”,但是,当我从命令行尝试它时,它确实工作!?win32上的Python 2.7.1(r271:86832,2010年11月27日,18:30:46)[MSC v.1500 32位(英特尔)]键入“帮助”、“版权”、“信用”或“许可证”以了解更多信息。>>>导入json>>>打印json.JSONDecoder>>>