def _process_response(self, resp, backoff): """ Process the response from the server """ success = True resp_data = None not_a_server_error = resp.status < 500 if not_a_server_error: resp_data = _decode_body(resp) a_client_error = resp.status >= 400 if a_client_error: raise exceptions.get(resp.status, resp_data) return resp_data, success, backoff else: # A server error, wait and retry backoff = self.backoff_logic(backoff) log.info("%s: waiting %s before re-trying" % (resp.status, backoff)) time.sleep(backoff) return None, not success, backoff
def _process_response(self, resp, backoff): """ Process the response from the server """ success = True resp_data = None not_a_server_error = resp.status < 500 if not_a_server_error: body = resp.read() if body: resp_data = json.loads(body.decode(_getcharset(resp))) log.debug("body(<-): %s" % body) a_client_error = resp.status >= 400 if a_client_error: raise exceptions.get(resp.status, resp_data) return resp_data, success, backoff, resp.status else: # A server error, wait and retry backoff = self.backoff_logic(backoff) log.debug("%s: waiting %s before re-trying" % (resp.status, backoff)) time.sleep(backoff) return None, not success, backoff, resp.status
def _process_response(self, resp, backoff): """ Process the response from the server """ success = True resp_data = None not_a_server_error = resp.status < 500 if not_a_server_error: body = resp.read() if body: resp_data = json.loads(body.decode(_getcharset(resp))) log.info("body(<-): %s" % body) a_client_error = resp.status >= 400 if a_client_error: raise exceptions.get(resp.status, resp_data) return resp_data, success, backoff else: # A server error, wait and retry backoff = self.backoff_logic(backoff) log.info("%s: waiting %s before re-trying" % (resp.status, backoff)) time.sleep(backoff) return None, not success, backoff
def _mexe(self, path, method="GET", query_props=None, headers=None): """Internal method for exeucting a command""" from httplib import HTTPSConnection import urllib import base64 import json success = False backoff = 1 if headers is None: headers = {} headers['Authorization'] = "Basic " + base64.b64encode(self.username+":"+self.api_key).strip() resp_data = None while not success: conn = HTTPSConnection(self.hostname,timeout=10) uri = self.base_path + path body = None if query_props: if method == "POST": body = json.dumps(query_props) headers['Content-Type'] = "application/json" else: uri += "?" + urllib.urlencode(query_props) log.info("%s %s" % (method,uri)) conn.request(method,uri,body=body,headers=headers) resp = conn.getresponse() if resp.status < 500: body = resp.read() if body: try: resp_data = json.loads(body) except: pass if resp.status >= 400: raise exceptions.get(resp.status, resp_data) success = True else: backoff += backoff*2 log.info("%s: waiting %s before re-trying" % (resp.status, backoff)) time.sleep(backoff) return resp_data