Websocket 如何将邮递员的uuid接收到tornado应用程序中?
我已经用uuid将我的模型保存在弹性数据库中,我使用该uuid从Postman调用tornado应用程序,uuid拥有我的模型,我应该如何在我的requestHandler中的POST方法中接收该模型,下面是代码Websocket 如何将邮递员的uuid接收到tornado应用程序中?,websocket,tornado,Websocket,Tornado,我已经用uuid将我的模型保存在弹性数据库中,我使用该uuid从Postman调用tornado应用程序,uuid拥有我的模型,我应该如何在我的requestHandler中的POST方法中接收该模型,下面是代码 class myHandler(RequestHandler): _thread_pool = ThreadPoolExecutor(max_workers=10) #My data base url def initialize(self):
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是我从postman收到的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
url=[(r/(-P[a-zA-Z0-9][+)/predict”,myHandler)
#从邮递员那里我称之为
http://127.0.0.1:8888/model_name/predict
匹配url和post函数中的名称“model\u 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
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
url=[(r/(-P[a-zA-Z0-9.-]+)/predict”,myHandler)
#从邮递员那里我称之为
http://127.0.0.1:8888/d460e889-6860-4fb4-b040-fee70c96a029.mods/predict
此捕获组的名称--(?P[a-zA-Z0-9\]+)
--是id
,但在您的处理程序中,您正在接受model\u id
。或者将捕获组的名称更改为model\u id
,或者将方法中的参数名称更改为id
。谢谢,我更改了uuid,也使用了相同的(?.P[a-zA-Z0-9\+)它工作了嗨,如果你已经解决了你的问题,请给你的问题添加一个答案并接受你的答案,这样问题就结束了。嗨,是的,根据你之前的评论,我在url中使用了模型id=[(r/(-P[a-zA-Z0-9\]+)/predict],myHandler)和regex[a-zA-Z0-9\]+,谢谢