This commit is contained in:
SpootDev 2016-03-30 22:32:59 -05:00
parent 0fc7fbd3b2
commit b8a5f9c913

View file

@ -60,8 +60,6 @@ class ConnectUtils():
def startSession(self): def startSession(self):
log = self.logMsg
self.deviceId = self.clientInfo.getDeviceId() self.deviceId = self.clientInfo.getDeviceId()
# User is identified from this point # User is identified from this point
@ -75,7 +73,7 @@ class ConnectUtils():
if self.sslclient is not None: if self.sslclient is not None:
verify = self.sslclient verify = self.sslclient
except: except:
log("Could not load SSL settings.", 1) self.logMsg("Could not load SSL settings.", 1)
# Start session # Start session
self.c = requests.Session() self.c = requests.Session()
@ -85,7 +83,7 @@ class ConnectUtils():
self.c.mount("http://", requests.adapters.HTTPAdapter(max_retries=1)) self.c.mount("http://", requests.adapters.HTTPAdapter(max_retries=1))
self.c.mount("https://", requests.adapters.HTTPAdapter(max_retries=1)) self.c.mount("https://", requests.adapters.HTTPAdapter(max_retries=1))
log("Requests session started on: %s" % self.server, 1) self.logMsg("Requests session started on: %s" % self.server, 1)
def stopSession(self): def stopSession(self):
try: try:
@ -95,8 +93,7 @@ class ConnectUtils():
def getHeader(self, authenticate=True): def getHeader(self, authenticate=True):
clientInfo = self.clientInfo version = self.clientInfo.getVersion()
version = clientInfo.getVersion()
if not authenticate: if not authenticate:
# If user is not authenticated # If user is not authenticated
@ -125,10 +122,9 @@ class ConnectUtils():
def doUrl(self, url, data=None, postBody=None, rtype="GET", def doUrl(self, url, data=None, postBody=None, rtype="GET",
parameters=None, authenticate=True, timeout=None): parameters=None, authenticate=True, timeout=None):
log = self.logMsg
window = utils.window window = utils.window
log("=== ENTER connectUrl ===", 2) self.logMsg("=== ENTER connectUrl ===", 2)
default_link = "" default_link = ""
if timeout is None: if timeout is None:
timeout = self.timeout timeout = self.timeout
@ -213,25 +209,25 @@ class ConnectUtils():
verify=verifyssl) verify=verifyssl)
##### THE RESPONSE ##### ##### THE RESPONSE #####
log(r.url, 1) self.logMsg(r.url, 1)
log(r, 1) self.logMsg(r, 1)
if r.status_code == 204: if r.status_code == 204:
# No body in the response # No body in the response
log("====== 204 Success ======", 1) self.logMsg("====== 204 Success ======", 1)
elif r.status_code == requests.codes.ok: elif r.status_code == requests.codes.ok:
try: try:
# UNICODE - JSON object # UNICODE - JSON object
r = r.json() r = r.json()
log("====== 200 Success ======", 1) self.logMsg("====== 200 Success ======", 1)
log("Response: %s" % r, 1) self.logMsg("Response: %s" % r, 1)
return r return r
except: except:
if r.headers.get('content-type') != "text/html": if r.headers.get('content-type') != "text/html":
log("Unable to convert the response for: %s" % url, 1) self.logMsg("Unable to convert the response for: %s" % url, 1)
else: else:
r.raise_for_status() r.raise_for_status()
@ -242,8 +238,8 @@ class ConnectUtils():
pass pass
except requests.exceptions.ConnectTimeout as e: except requests.exceptions.ConnectTimeout as e:
log("Server timeout at: %s" % url, 0) self.logMsg("Server timeout at: %s" % url, 0)
log(e, 1) self.logMsg(e, 1)
except requests.exceptions.HTTPError as e: except requests.exceptions.HTTPError as e:
@ -259,11 +255,11 @@ class ConnectUtils():
pass pass
except requests.exceptions.SSLError as e: except requests.exceptions.SSLError as e:
log("Invalid SSL certificate for: %s" % url, 0) self.logMsg("Invalid SSL certificate for: %s" % url, 0)
log(e, 1) self.logMsg(e, 1)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
log("Unknown error connecting to: %s" % url, 0) self.logMsg("Unknown error connecting to: %s" % url, 0)
log(e, 1) self.logMsg(e, 1)
return default_link return default_link