'Connect to qBittorrent Web UI. Username and password not necessary
if \'Bypass authentication for localhost\' is checked and host is
\'localhost\'.'

def connect(self, config):

    self.session = Session()
    self.url = u'http://{}:{}'.format(config[u'host'], config[u'port'])
    if (config.get(u'username') and config.get(u'password')):
        response = self.session.post((self.url + u'/login'), data={u'username': config[u'username'], u'password': config[u'password']})
        if (response == u'Fails.'):
            log.debug(u'Error    connecting    to    qBittorrent')
            raise plugin.PluginError(u'Authentication    failed.')
    log.debug(u'Successfully    connected    to    qBittorrent')
    self.connected = True
