websocket - 如何将邮递员的 uuid 接收到龙卷风应用程序中?
问题描述
我已经使用 uuid 将我的模型保存在弹性数据库中,我使用该 uuid 从 Postman 调用我的 tornado 应用程序,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
解决方案
匹配 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
推荐阅读
- sed - 使用 sed 将标题批量插入 CSV 文件
- php - Laravel 5.2 基于用户的动态环境变量
- r - 如何将对应的统计数据从线性回归模型导出到 R 中的表格?
- netlogo - NetLogo - 所有海龟的总和列表
- javascript - ipcRenderer.on() 函数未接收到 mainWindow.webContents.send()
- php - 如何在链接codeigniter中传递id值
- applescript - 如何修复程序中未定义的变量?
- pyspark - NullPointerException 与 pyspark 数据框
- android - CameraPreview 在开始时未显示,但在热重新加载后
- regex - 需要一个在表达式后包含所有字符的正则表达式