def handleOperate(cmd):
logging.info("handleOperate: Start to handle operate. cmd=%s", str(cmd))
url = client.protocol + client.localHostPort + "/command"
command = {"type": cmd['type'],
"boxid": cmd['boxid'],
"data": "",
}
del cmd['type']
command['data'] = json.dumps(cmd)
headers, body = createFormData(command)
operate_request = HTTPRequest(url=url, method="POST", headers=headers, body=body)
response = yield client.http_client.fetch(operate_request, request_timeout=60)
if response.error:
logging.error("handleOperate: Failed to send operate. error=%s", response.error)
else:
logging.info("handleOperate: Operate result. response.body=%r", response.body)
res = json_decode(response.body)
if res["ret_value"] != 0:
#need login
logging.warn("handleOperate: Failed to execute [%s] operation. ret_val=", res["ret_value"])
logging.info("handleOperate: End to handle operate.")
评论列表
文章目录