【发布时间】:2017-04-28 04:13:10
【问题描述】:
我是cherrypy 的新手,我选择它来创建用于其他Web 应用程序的Web 服务。我想使用 apache2 和 mod_wsgi 运行它。我遵循了相当 old documentation 并且 hello world 示例工作得很好。
我现在正在查看教程,当然还有REST tutorial。但是我无法让它运行。我在 apache 日志中收到状态 500 和错误:
TypeError: expose_() missing 1 required positional argument: 'func'
为了做到这一点,我调整了教程中的脚本,类似于 hello world 示例以使用 apache:
import sys
sys.stdout = sys.stderr
import random
import string
import cherrypy
cherrypy.config.update({'environment': 'embedded'})
@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)
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)
我做错了什么?
【问题讨论】:
标签: python apache rest cherrypy