如何将邮递员的uuid接收到龙卷风应用程序中?

时间:2019-07-12 06:36:52

标签: websocket tornado

我已经用uuid将模型保存在弹性数据库中,我使用那个uuid从Postman调用了我的龙卷风应用程序,uuid正在建立我的模型,我该如何在我的requestHandler中的POST方法中接收它,下面是代码

class myHandler(RequestHandler):  
    _thread_pool = ThreadPoolExecutor(max_workers=10)

    #My data base url
    def initialize(self): 
        self.db = self.settings['db']

    #POST method to receive data and model
    @gen.coroutine
    def post(self, model_id):
        try:
            data = tornado.escape.json_decode(self.request.body)
            yield self.predict(model_id, self.db, data)
        except Exception:
            self.respond('server_error', 500)

    ###here I have predict methods that receive the model_id and pass###

post方法参数中的model_id是我从邮递员那里收到的uuid

我的应用程序调用看起来像

elastic_url = os.environ.get('ELASTICSEARCH_URL', 'localhost:9200')
define('port', default=8888, help='Tornado port to listen on')

def make_app():  
    url = [(r"/uuid/predict", myHandler)]
    return Application(url, db=elastic_url, debug=True, autoreload=False)

if __name__ == "__main__":
    application = make_app()
    http_server = HTTPServer(application)
    http_server.listen(options.port)
    IOLoop.current().start() 

在POSTMAN中,我将API称为

http://127.0.0.1:8888/9cd68748-a3b5-4bc3-994d-16e921103cb2/predict

如果我没有uuid,我会收到如下所示的正则表达式

url = [(r"/(?P<id>[a-zA-Z0-9_]+)/predict", myHandler)
#From POSTMAN I call as
http://127.0.0.1:8888/model_name/predict

1 个答案:

答案 0 :(得分:0)

在url和post函数中匹配名称'model_id'

    @gen.coroutine
    def post(self, model_id):
        try:
            data = tornado.escape.json_decode(self.request.body)
            yield self.predict(model_id, self.db, data)
        except Exception:
            self.respond('server_error', 500)

,并按如下所示使用了网址

url = [(r"/(?P<model_id>[a-zA-Z0-9_.-]+)/predict", myHandler)
#From POSTMAN I call as
http://127.0.0.1:8888/d460e889-6860-4fb4-b040-fee70c96a029.mods/predict