diff --git a/uai/cmd/base_cmd.py b/uai/cmd/base_cmd.py index d62b3f0..4eaed9b 100644 --- a/uai/cmd/base_cmd.py +++ b/uai/cmd/base_cmd.py @@ -296,7 +296,7 @@ def _cmd_common_request(self): self.cmd_params) uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) - self.rsp = json.loads(r.text, 'utf-8') + self.rsp = json.loads(r.text, encoding='utf-8') if self.rsp["RetCode"] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8'))) raise RuntimeError("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8'))) @@ -304,36 +304,6 @@ def _cmd_common_request(self): del self.rsp['Action'] uai_logger.info("{0} Success: {1}".format(self.cmd_params["Action"], get_response(self.rsp,0))) - - # def _cmd_writefile_package(self, filepath): - # if self.cmd_params.has_key('Signature'): - # self.cmd_params.pop('Signature') - # self.cmd_params['Signature'] = _verfy_ac(self.conf_params['private_key'], - # self.cmd_params) - # uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params))) - # r = requests.get(self.cmd_url, params=self.cmd_params) - # rsp = json.loads(r.text, 'utf-8') - # if rsp["RetCode"] != 0: - # uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8'))) - # raise RuntimeError( - # "{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8'))) - # else: - # with open(filepath, 'w') as f: - # json.dump(rsp["PkgSet"], f) - - - # def cmd(self, params): - # """ Create the task of specified task id - # """ - # self.conf_params = params - # print "+++++in cmd func+++++" - # print self.conf_params - # if not self.conf_params: - # print "HERE!" - # self._load_args() - # self._format_request_param() - # self._cmd_request() - def cmd(self): """ Create the task of specified task id """ diff --git a/uaitrain/api/base_op.py b/uaitrain/api/base_op.py index 944e615..dad1f90 100644 --- a/uaitrain/api/base_op.py +++ b/uaitrain/api/base_op.py @@ -61,7 +61,7 @@ def __init__(self, action, pub_key, priv_key, project_id, region, zone): pass def _cmd_common_request(self): - if self.cmd_params.has_key('Signature'): + if ('Signature' in self.cmd_params) is True: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = _verfy_ac(self.priv_key, self.cmd_params) @@ -69,7 +69,7 @@ def _cmd_common_request(self): uai_logger.info(self.cmd_params) uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) - rsp = json.loads(r.text, 'utf-8') + rsp = json.loads(r.text, encoding='utf-8') if rsp['RetCode'] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params[PARAM_ACTION], rsp['RetCode'], rsp['Message'].encode('utf-8'))) diff --git a/uaitrain/cmd/base_cmd.py b/uaitrain/cmd/base_cmd.py index d6b1e82..3dd3298 100644 --- a/uaitrain/cmd/base_cmd.py +++ b/uaitrain/cmd/base_cmd.py @@ -110,13 +110,13 @@ def _cmd_request(self): self._cmd_common_request() def _cmd_common_request(self): - if self.cmd_params.has_key('Signature'): + if ('Signature' in self.cmd_params) is True: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = _verfy_ac(self.conf_params['private_key'], self.cmd_params) uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) - self.rsp = json.loads(r.text, 'utf-8') + self.rsp = json.loads(r.text, encoding='utf-8') if self.rsp["RetCode"] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8'))) raise RuntimeError("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8'))) @@ -126,13 +126,13 @@ def _cmd_common_request(self): def _cmd_writefile_package(self, filepath): - if self.cmd_params.has_key('Signature'): + if ('Signature' in self.cmd_params) is True: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = _verfy_ac(self.conf_params['private_key'], self.cmd_params) uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) - rsp = json.loads(r.text, 'utf-8') + rsp = json.loads(r.text, encoding='utf-8') if rsp["RetCode"] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8'))) raise RuntimeError(