尝试在cherrypy文档页面上按照教程7来创建REST样式API。来自tutorial,
的复制粘贴代码import random
import string
import cherrypy
@cherrypy.expose
class StringGeneratorWebService(object):
@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)
if __name__ == '__main__':
conf = {
'/': {
'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
'tools.sessions.on': True,
'tools.response_headers.on': True,
'tools.response_headers.headers': [('Content-Type', 'text/plain')],
}
}
cherrypy.quickstart(StringGeneratorWebService(), '/', conf)
但是在运行时给出了错误
File "H:/researchInstrumentCatalog/dqapi/core/test.py", line 36, in <module>
cherrypy.quickstart(test(), '/', conf)
TypeError: expose_() takes exactly 1 argument (0 given)
我正在运行cherrypy 3.8,因此this question没有帮助