我在龙卷风服务器上发布帖子请求时遇到上述错误。
我有一个像
这样的课程class RestRequestHandler(RequestHandler):
def async_get(self, *args, **kwargs):
pass
def async_post(self, *args, **kwargs):
pass
上面的类我要导入另一个py文件
class get_question_details(RestRequestHandler):
def async_post(self, activity_id, attempt_id, quiz_id, question_id,
questionusage_id, slot, user_name, courseshortname):
client = get_moodle_client()
当我提出此请求时,我收到警告,如
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 421, in _run_callback
callback()
File "/usr/local/lib/python2.7/dist-packages/gameonapi/server/rest.py", line 142, in async_post_callback
self.return_ok(result)
File "/usr/local/lib/python2.7/dist-packages/gameonapi/server/rest.py", line 214, in return_ok
self.write (result)
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line 489, in write
raise RuntimeError("Cannot write() after finish(). May be caused "
RuntimeError: Cannot write() after finish(). May be caused by using async operations without the @asynchronous decorator.
从错误中我理解导致问题因为我没有使用龙卷风@asynchronous
但是在使用之后我仍然得到同样的警告。
请告诉我,我在这里做错了什么。
答案 0 :(得分:0)
也许您应该为您的班级注册Post方法,因为我不知道龙卷风如何以您的方式处理POST请求。 检查这个问题。 How to use POST method in Tornado?
答案 1 :(得分:0)
如果您不使用@asynchronous
装饰器,则会在功能完成前自动调用self.finish()
函数
你应该拥有的是
class RestRequestHandler(RequestHandler):
@tornado.web.asynchronous
def async_get(self, *args, **kwargs):
self.write('ok')
self.finish()
@tornado.web.asynchronous
def async_post(self, *args, **kwargs):
self.write('ok')
self.finish()
通过这种方式,系统可以让您有机会写出您想写的任何内容。写完后,您需要调用self.finish
方法告诉系统您已完成。