python - Tornado GET 套接字挂断
问题描述
我在 Tornado 中做了一个 REST 服务。我尝试了一个带有 JSON 参数的 GET 并且一切正常。但是当我尝试使用 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
解决方案
prepare()
的函数出现致命错误RequestHandler
。所以服务器正确启动,但没有收到 POST。
推荐阅读
- sql - 将多个列条目添加到单行中
- c++ - 队列 - 服务器横幅行为
- java - JUnit 5:如何断言在 Scala 中引发了异常?
- docusignapi - 重定向到发件人视图 URL 显示错误
- java - 取消选择 JTree
- android - Kotlin 结构化类约 3000 行 JSON(反)序列化 - 可访问性/存储?
- html - 字体真棒图标没有出现在文本框中
- arrays - 如何在数组中找到最大值和前一个最大值
- react-native - Expo.launchCameraAsync 自定义图像视图?
- android - 通过添加工具栏时,CoordinatorLayout 滚动不起作用