def _send_get_request(self): r = requests.get(self.cmd_url, data=json.dumps(self.cmd_params), headers=self.cmd_header) rsp = json.loads(r.text, encoding='utf-8') if rsp['RetCode'] != 0: print("Call {0} fail: [{1}]{2}".format(self.cmd_url, rsp["RetCode"], rsp["Message"].encode('utf-8'))) uai_logger.error("Call {0} fail: [{1}]{2}".format(self.cmd_url, rsp["RetCode"], rsp["Message"].encode('utf-8'))) return False, rsp else: print("Call {0} success: {1}".format(self.cmd_url, get_response(rsp, 0))) uai_logger.info("Call {0} success: {1}".format(self.cmd_url, get_response(rsp, 0))) return True, rsp
def _send_post_request_with_multi_part(self): # m = MultipartEncoder(fields=self.cmd_params) # self.cmd_header['Content-Type'] = m.content_type r = requests.post(self.cmd_url, files=self.cmd_params, headers=self.cmd_header) rsp = json.loads(r.text, encoding='utf-8') if rsp['RetCode'] != 0: print("Call {0} fail: [{1}]{2}".format(self.cmd_url, rsp["RetCode"], rsp["Message"].encode('utf-8'))) uai_logger.error("Call {0} fail: [{1}]{2}".format(self.cmd_url, rsp["RetCode"], rsp["Message"].encode('utf-8'))) return False, rsp else: print("Call {0} success: {1}".format(self.cmd_url, get_response(rsp, 0))) uai_logger.info("Call {0} success: {1}".format(self.cmd_url, get_response(rsp, 0))) return True, rsp
def _cmd_common_request(self): if ('Signature' in self.cmd_params) is True: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = verfy_ac(self.private_key, self.cmd_params) uai_logger.info("Signature: {0}".format(self.cmd_params['Signature'])) uai_logger.info(self.cmd_params) r = requests.get(self.cmd_url, params=self.cmd_params) rsp = json.loads(r.text, encoding="utf-8") if rsp["RetCode"] != 0: uai_logger.error("{0} fail: [{1}]{2}".format(self.action, rsp["RetCode"], rsp["Message"].encode('utf-8'))) return False, rsp else: del rsp['Action'] print("{0} success: {1}".format(self.action, get_response(rsp, 0))) uai_logger.info("{0} success: {1}".format(self.action, get_response(rsp, 0))) return True, rsp