Tornado GET 套接字挂断
Tornado GET socket hang up
我在 Tornado 中做了一个 REST 服务。我已经尝试使用 JSON 参数进行 GET 并且一切正常。但是当我尝试使用 urls 中的参数时,我收到邮递员的“套接字挂断”错误。
这是url发送的
http://127.0.0.1:8080/scenarios/asyncexec?project_name=LBP22&scenario_name=6a27351e-e51f-4349-89d8-a3e326a5bd12
和 GET 的处理程序
def get(self):
# GET function for checking the status of execution
project_name = self.get_argument('project_name')
scenario_name = self.get_argument('scenario_name')
Loggers.access.info("Polling for exec status")
running = False
save_exec_element = None
for exec_element in strategy_lab_config.Scenarios.Execute.exec_list:
if exec_element[1] == project_name and \
exec_element[2] == scenario_name:
exec_future = exec_element[0]
if exec_future.running():
self._generate_output_json_from_dict({"execution_status": "RET_OK_PROCESSING"})
running = True
break
elif exec_future.done():
save_exec_element = exec_element
try:
output = exec_future.result()
scenario = {
'project_name': project_name,
'scenario_name': scenario_name,
"execution_status": 'RET_OK_DONE',
"output": output
}
self._generate_output_json_from_dict(scenario)
break
except Exception as exec_exc:
scenario = {
'project_name': project_name,
'scenario_name': scenario_name,
"execution_status": 'RET_ERR_FAIL',
"error_message": str(exec_exc),
"traceback": "".join(traceback.TracebackException.from_exception(exec_exc).format())
}
self._generate_output_json_from_dict(scenario)
break
else:
self._generate_output_json_from_dict({"execution_status": "RET_ERR_NOT_EXIST"})
return
请注意,之前的版本与 JSON 一起使用,一切正常。
我这里有处理程序定义
class Application(tornado.web.Application):
def __init__(self):
handlers = [
("/datasets/add", DatasetAdd),
("/projects/create", ProjectCreate),
("/projects/delete", ProjectDelete),
("/scenarios/execute", ScenarioExecute),
("/scenarios/asyncexec", AsyncScenarioExecute),
("/scenarios/tune", ScenarioTune),
("/scenarios/whatif", ScenarioWhatIfAnalysis)
]
tornado.web.Application.__init__(self, handlers, debug=True)
pass
RequestHandler
的 prepare()
函数出现致命错误。所以服务器正常启动,但是没有收到POST.
我在 Tornado 中做了一个 REST 服务。我已经尝试使用 JSON 参数进行 GET 并且一切正常。但是当我尝试使用 urls 中的参数时,我收到邮递员的“套接字挂断”错误。
这是url发送的
http://127.0.0.1:8080/scenarios/asyncexec?project_name=LBP22&scenario_name=6a27351e-e51f-4349-89d8-a3e326a5bd12
和 GET 的处理程序
def get(self):
# GET function for checking the status of execution
project_name = self.get_argument('project_name')
scenario_name = self.get_argument('scenario_name')
Loggers.access.info("Polling for exec status")
running = False
save_exec_element = None
for exec_element in strategy_lab_config.Scenarios.Execute.exec_list:
if exec_element[1] == project_name and \
exec_element[2] == scenario_name:
exec_future = exec_element[0]
if exec_future.running():
self._generate_output_json_from_dict({"execution_status": "RET_OK_PROCESSING"})
running = True
break
elif exec_future.done():
save_exec_element = exec_element
try:
output = exec_future.result()
scenario = {
'project_name': project_name,
'scenario_name': scenario_name,
"execution_status": 'RET_OK_DONE',
"output": output
}
self._generate_output_json_from_dict(scenario)
break
except Exception as exec_exc:
scenario = {
'project_name': project_name,
'scenario_name': scenario_name,
"execution_status": 'RET_ERR_FAIL',
"error_message": str(exec_exc),
"traceback": "".join(traceback.TracebackException.from_exception(exec_exc).format())
}
self._generate_output_json_from_dict(scenario)
break
else:
self._generate_output_json_from_dict({"execution_status": "RET_ERR_NOT_EXIST"})
return
请注意,之前的版本与 JSON 一起使用,一切正常。
我这里有处理程序定义
class Application(tornado.web.Application):
def __init__(self):
handlers = [
("/datasets/add", DatasetAdd),
("/projects/create", ProjectCreate),
("/projects/delete", ProjectDelete),
("/scenarios/execute", ScenarioExecute),
("/scenarios/asyncexec", AsyncScenarioExecute),
("/scenarios/tune", ScenarioTune),
("/scenarios/whatif", ScenarioWhatIfAnalysis)
]
tornado.web.Application.__init__(self, handlers, debug=True)
pass
RequestHandler
的 prepare()
函数出现致命错误。所以服务器正常启动,但是没有收到POST.