def login(host,username,password): client = httplib2.Http() client.add_credentials(username,password) url = 'http://{}{}{}'.format(host,uriBase,'/auth/login') auth = base64.encodestring(username + ':' + password) auth_header = { 'Authorization' : 'Basic ' + auth } logger.debug("URL: %s", url) token = None try: r, c = client.request(url,method=GET, headers=auth_header ) logger.debug("Response: %s",r) logger.debug("Content: %s",c) if r is not None and r.status == 200: data = response.BaseResponse(c) if data.get_payload_type() == _AUTH_TYPE: token = data.get_payload_value('token') else: pass except: logger.warn("Error Connecting to LOGIN API: %s", url) return token
def on_messageQueue(self, ws, message): self.queue.put_nowait(response.BaseResponse(message))