def _make_opener(realm, base_url, username, password): """uTorrent API need HTTP Basic Auth and cookie support for token verify.""" auth = HTTPBasicAuthHandler() auth.add_password(realm=realm, uri=base_url, user=username, passwd=password) opener = build_opener(auth) install_opener(opener) cookie_jar = http_cookiejar.CookieJar() cookie_handler = HTTPCookieProcessor(cookie_jar) handlers = [auth, cookie_handler] opener = build_opener(*handlers) return opener
def __init__(self): host = lazylibrarian.CONFIG['QBITTORRENT_HOST'] port = check_int(lazylibrarian.CONFIG['QBITTORRENT_PORT'], 0) if not host or not port: logger.error('Invalid Qbittorrent host or port, check your config') if not host.startswith("http://") and not host.startswith("https://"): host = 'http://' + host if host.endswith('/'): host = host[:-1] if host.endswith('/gui'): host = host[:-4] host = "%s:%s" % (host, port) self.base_url = host self.username = lazylibrarian.CONFIG['QBITTORRENT_USER'] self.password = lazylibrarian.CONFIG['QBITTORRENT_PASS'] self.cookiejar = http_cookiejar.CookieJar() self.opener = self._make_opener() self._get_sid(self.base_url, self.username, self.password) self.api = self._api_version()