Search code examples
pythonpython-3.xrestpostmantornado

Tornado GET socket hang up


I have made a REST service in Tornado. I have tried a GET with JSON arguments and all works fine. But when I try with parameters in urls, I receive with postman a "socket hang up" error.

This is the url sent

http://127.0.0.1:8080/scenarios/asyncexec?project_name=LBP22&scenario_name=6a27351e-e51f-4349-89d8-a3e326a5bd12

and the handler for 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

Note that the previous version was with JSON and it all worked fine.

Here I have the handlers definitions

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

Solution

  • There was a fatal error on the prepare() function of RequestHandler. So the server started correctly, but without receiving POST.