0
REST 스타일 API를 생성하기위한 cherrypy 문서 페이지의 튜토리얼 7을 따르려고합니다. 복사 - 붙여 넣기 tutorial의 코드,Cherrypy REST 튜토리얼은 TypeError를 반환합니다. _expose()는 정확히 하나의 인수를받습니다
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)
하지만 cherrypy 3.8을 실행하고
File "H:/researchInstrumentCatalog/dqapi/core/test.py", line 36, in <module>
cherrypy.quickstart(test(), '/', conf)
TypeError: expose_() takes exactly 1 argument (0 given)
오류를 부여하고 실행할 때, 따라서 this question는 링크 된 질문에
오, 죄송합니다. 질문을 잘못 읽었습니다. –
나는 exposed = True를 더 일찍 추가하려했으나 expose 데코레이터를 제거하지 않았다. 그래서 후자가 문제를 해결했다. –