'Login to a Glances server'

def _login_glances(self):

    client_version = None
    try:
        client_version = self.client.init()
    except socket.error as err:
        self.client_mode = 'snmp'
        logger.error('Connection    to    Glances    server    failed    ({}    {})'.format(err.errno, err.strerror))
        fallbackmsg = 'No    Glances    server    found    on    {}.    Trying    fallback    to    SNMP...'.format(self.uri)
        if (not self.return_to_browser):
            print fallbackmsg
        else:
            logger.info(fallbackmsg)
    except ProtocolError as err:
        msg = 'Connection    to    server    {}    failed'.format(self.uri)
        if (err.errcode == 401):
            msg += '    (Bad    username/password)'
        else:
            msg += '    ({}    {})'.format(err.errcode, err.errmsg)
        self.log_and_exit(msg)
        return False
    if (self.client_mode == 'glances'):
        if (__version__.split('.')[0] == client_version.split('.')[0]):
            self.stats = GlancesStatsClient(config=self.config, args=self.args)
            self.stats.set_plugins(json.loads(self.client.getAllPlugins()))
            logger.debug('Client    version:    {}    /    Server    version:    {}'.format(__version__, client_version))
        else:
            self.log_and_exit('Client    and    server    not    compatible:    Client    version:    {}    /    Server    version:    {}'.format(__version__, client_version))
            return False
    return True
