Python cherrypy中的RESTful web服务示例

Python cherrypy中的RESTful web服务示例,python,rest,cherrypy,Python,Rest,Cherrypy,我正在尝试用python编写一个RESTful web服务。但是,在尝试上给出的教程时,我最终出现了如下错误 Traceback (most recent call last): File "rest.py", line 35, in <module> cherrypy.quickstart(StringGeneratorWebService(), '/', conf) TypeError: expose_() takes exactly 1 argument (0 gi

我正在尝试用python编写一个RESTful web服务。但是,在尝试上给出的教程时,我最终出现了如下错误

Traceback (most recent call last):
  File "rest.py", line 35, in <module>
    cherrypy.quickstart(StringGeneratorWebService(), '/', conf)
TypeError: expose_() takes exactly 1 argument (0 given)
回溯(最近一次呼叫最后一次):
文件“rest.py”,第35行,在
快速启动(StringGeneratorWebService(),“/”,conf)
TypeError:expose_389;()正好接受1个参数(给定0)
其中rest.py是我的文件,其中包含与网站上完全相同的代码,副标题为“让我们休息一下”

我很清楚,很明显,从错误消息中,我缺少了一个应该传入的参数。但我不清楚我到底应该在哪里修改该准则以使其生效


我试着在35号线上修理一些东西,但没有任何帮助,我被卡住了!请帮我弄清楚这一点,或者请给出一些代码片段,以便在cherrypy中创建REST服务。谢谢大家!

您正在使用的CherryPy版本(
3.2.2
)不支持类上的
CherryPy.expose
decorator,该功能被禁用

您可以使用将
exposed
属性设置为
True
的旧语法(它也与较新版本兼容)

这门课的结局是:

class StringGeneratorWebService(object):
    exposed = True

    @cherrypy.tools.accept(media='text/plain')
    def GET(self):
        return cherrypy.session['mystring']

    def POST(self, length=8):
        some_string = ''.join(random.sample(string.hexdigits, int(length)))
        cherrypy.session['mystring'] = some_string
        return some_string

    def PUT(self, another_string):
        cherrypy.session['mystring'] = another_string

    def DELETE(self):
        cherrypy.session.pop('mystring', None)

您使用的是哪个版本的CherryPy和Python?我使用的是Python版本2.7和CherryPy版本3.2.2