Python http.cookiejar.LWPCookieJar() Examples

The following are 28 code examples of http.cookiejar.LWPCookieJar(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module http.cookiejar , or try the search function .
Example #1
Source File: yahoo.py    From yahoo-group-archiver with MIT License 7 votes vote down vote up
def init_cookie_jar(cookie_file=None, cookie_t=None, cookie_y=None, cookie_euconsent=None):
    cookie_jar = LWPCookieJar(cookie_file) if cookie_file else RequestsCookieJar()

    if cookie_file and os.path.exists(cookie_file):
        cookie_jar.load(ignore_discard=True)

    if args.cookie_t:
        cookie_jar.set_cookie(create_cookie('T', cookie_t))
    if cookie_y:
        cookie_jar.set_cookie(create_cookie('Y', cookie_y))
    if cookie_euconsent:
        cookie_jar.set_cookie(create_cookie('EuConsent', cookie_euconsent))

    if cookie_file:
        cookie_jar.save(ignore_discard=True)

    return cookie_jar 
Example #2
Source File: 18 github_login.py    From Python-Spider with Apache License 2.0 6 votes vote down vote up
def __init__(self):
        # url
        self.loginUrl = 'https://github.com/login'
        self.postUrl = 'https://github.com/session'
        self.profileUrl = 'https://github.com/settings/profile'

        # 设置请求头
        self.headers = {
            'Referer': 'https://github.com/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
            'Host': 'github.com'
        }

        # 设置session
        self.session = requests.session()
        # 生成github_cookie文件
        self.session.cookies = cookielib.LWPCookieJar(filename='github_cookie') 
Example #3
Source File: baidu_count_login.py    From Daily_scripts with MIT License 6 votes vote down vote up
def get_cookies():
    """获取百度 cookies, 并写入文件."""
    headers = {
        "User-Agent": (
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36"
            "(KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"
        )
    }
    save_cookies_file = 'cookies.txt'
    jar = cookielib.LWPCookieJar(save_cookies_file)
    sess = requests.session()
    sess.headers = headers
    sess.cookies = jar
    sess.get('http://tieba.baidu.com/')
    jar.save(ignore_expires=True, ignore_discard=True)
    return jar 
Example #4
Source File: zhihu_login.py    From zhihu-login with MIT License 6 votes vote down vote up
def __init__(self, username: str = None, password: str = None):
        self.username = username
        self.password = password

        self.login_data = {
            'client_id': 'c3cef7c66a1843f8b3a9e6a1e3160e20',
            'grant_type': 'password',
            'source': 'com.zhihu.web',
            'username': '',
            'password': '',
            'lang': 'en',
            'ref_source': 'other_https://www.zhihu.com/signin?next=%2F',
            'utm_source': ''
        }
        self.session = requests.session()
        self.session.headers = {
            'accept-encoding': 'gzip, deflate, br',
            'Host': 'www.zhihu.com',
            'Referer': 'https://www.zhihu.com/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 '
                          '(KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36'
        }
        self.session.cookies = cookiejar.LWPCookieJar(filename='./cookies.txt') 
Example #5
Source File: WeiboSuperCommentScrapy.py    From WeiboSuperSpider with Apache License 2.0 6 votes vote down vote up
def get_cookies():
    # 加载cookie
    cookies = cookielib.LWPCookieJar("Cookie.txt")
    cookies.load(ignore_discard=True, ignore_expires=True)
    # 将cookie转换成字典
    cookie_dict = requests.utils.dict_from_cookiejar(cookies)
    return cookie_dict 
Example #6
Source File: decorators.py    From codechef-cli with GNU General Public License v3.0 6 votes vote down vote up
def login_required(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        is_logged_in = False
        if os.path.exists(COOKIES_FILE_PATH):
            cookiejar = LWPCookieJar(filename=COOKIES_FILE_PATH)
            cookiejar.load()

            if len(cookiejar):
                is_logged_in = True
            else:
                os.remove(COOKIES_FILE_PATH)
        if is_logged_in is False:
            return [{'code': 401}]
        return func(*args, **kwargs)
    return wrapper 
Example #7
Source File: Cspam.py    From s-mbf with MIT License 6 votes vote down vote up
def send(id,msg,lop):
		try:
			print()
			cjs = kuki('toket/kue.txt')
			cjs.load()
			br.set_cookiejar(cjs)
			for i in range(int(lop)):
				print("[!] sending messages to "+id)
				br.open('https://mbasic.facebook.com/messages/thread/'+id+'/')
				br.form = list(br.forms())[1]
				control = br.form.find_control("body")
				for control in br.form.controls:
					if control.type == "submit":
						control.disabled = True
				br["body"]=msg
				snd=br.submit().read()
				if 'send_success' in str(snd):
					print('[+] succes')
				else: print('[-] failed')
		except IndexError:
			print("[!] error when sending a message to",id) 
Example #8
Source File: Cspam.py    From s-mbf with MIT License 6 votes vote down vote up
def login():
		print("\n[!] checking cookies")
		time.sleep(1)
		s = ses()
		s.cookies = kuki('toket/kue.txt')
		try:
			fil=open('toket/kue.txt')
			fil.close()
		except FileNotFoundError:
			print("[!] cookies not found\n\n[!] please login in your facebook once again")
			email=input('[?] email/username: ')
			pw=prompt('[?] password: ',is_password=True)
			data = {'email':email,'pass':pw}
			url='https://mbasic.facebook.com/login'

			res = s.post(url,data=data).text
			if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
				s.cookies.save()
			else:
				exit('[!] fail login into your account') 
Example #9
Source File: Genkuki.py    From s-mbf with MIT License 6 votes vote down vote up
def login(self):
	global s
	print("\n[!] checking cookies")
	time.sleep(1)
	s = self.req
	s.cookies = kuki('toket/kue.txt')
	try:
		fil=open('toket/kue.txt')
		fil.close()
	except FileNotFoundError:
		print("[!] cookies not found\n\n[!] please login in your facebook once again")
		email=input('[?] email/username: ')
		pw=prompt('[?] password: ', is_password=True)
		data = {'email':email,'pass':pw}
		res = s.post('https://mbasic.facebook.com/login',data=data).text
		if 'logout.php' in str(res) or 'mbasic_logout_button' in str(res):
			s.cookies.save()
		else:
			exit('[!] fail login into your account')
	if 'True' in cek():
		pass
	else:
		exit() 
Example #10
Source File: Genkuki.py    From s-mbf with MIT License 6 votes vote down vote up
def cek():
	try:
		s.cookies=kuki('toket/kue.txt')
		s.cookies.load()
		cek=s.get('https://mbasic.facebook.com/me').text
		if 'mbasic_logout_button' in cek:
			print('[√] cookies valids\n')
			a='True'
			return a
		else:
			print('[!] cookies invalid')
			os.remove('toket/kue.txt')
			a='False'
			return a
	except:
		print('[!] cookies invalid')
		os.remove('toket/kue.txt')
		a='False'
		return a 
Example #11
Source File: query.py    From edce-client with MIT License 6 votes vote down vote up
def initSession():
	if edce.globals.debug:
		print(">>>>>>>>>>>>>>>> initSession")

	cookie_filename = edce.config.getString('paths','cookie_file')

	session = requests.Session()
	session.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Mobile/11D257'
	
	session.cookies = LWPCookieJar(cookie_filename)
	try:
		session.cookies.load(ignore_discard=True)
	except FileNotFoundError:
		session.cookies.save()

	return session 
Example #12
Source File: api.py    From musicbox with MIT License 5 votes vote down vote up
def __init__(self):
        self.header = {
            "Accept": "*/*",
            "Accept-Encoding": "gzip,deflate,sdch",
            "Accept-Language": "zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4",
            "Connection": "keep-alive",
            "Content-Type": "application/x-www-form-urlencoded",
            "Host": "music.163.com",
            "Referer": "http://music.163.com",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
        }

        self.storage = Storage()
        cookie_jar = LWPCookieJar(self.storage.cookie_path)
        cookie_jar.load()
        self.session = requests.Session()
        self.session.cookies = cookie_jar
        for cookie in cookie_jar:
            if cookie.is_expired():
                cookie_jar.clear()
                self.storage.database["user"] = {
                    "username": "",
                    "password": "",
                    "user_id": "",
                    "nickname": "",
                }
                self.storage.save()
                break 
Example #13
Source File: helpers.py    From codechef-cli with GNU General Public License v3.0 5 votes vote down vote up
def set_session_cookies(session):
    session.cookies = LWPCookieJar(filename=COOKIES_FILE_PATH) 
Example #14
Source File: api.py    From MusicBoxApi with MIT License 5 votes vote down vote up
def __init__(self):
        self.header = {
            'Accept': '*/*',
            'Accept-Encoding': 'gzip,deflate,sdch',
            'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
            'Connection': 'keep-alive',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Host': 'music.163.com',
            'Referer': 'http://music.163.com/search/',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36'  # NOQA
        }
        self.cookies = {'appver': '1.5.2'}
        self.playlist_class_dict = {}
        self.session = requests.Session()
        self.storage = Storage()
        self.session.cookies = LWPCookieJar(self.storage.cookie_path)
        try:
            self.session.cookies.load()
            cookie = ''
            if os.path.isfile(self.storage.cookie_path):
                self.file = open(self.storage.cookie_path, 'r')
                cookie = self.file.read()
                self.file.close()
            expire_time = re.compile(r'\d{4}-\d{2}-\d{2}').findall(cookie)
            if expire_time:
                if expire_time[0] < time.strftime('%Y-%m-%d', time.localtime(time.time())):
                    self.storage.database['user'] = {
                        'username': '',
                        'password': '',
                        'user_id': '',
                        'nickname': '',
                    }
                    self.storage.save()
                    os.remove(self.storage.cookie_path)
        except IOError as e:
            log.error(e)
            self.session.cookies.save() 
Example #15
Source File: NetUtils.py    From 12306 with MIT License 5 votes vote down vote up
def save_cookies(cookie_path):
        new_cookie_jar = cookiejar.LWPCookieJar(cookie_path)
        requests.utils.cookiejar_from_dict({c.name: c.value for c in EasyHttp.__session.cookies}, new_cookie_jar)
        new_cookie_jar.save(cookie_path, ignore_discard=True, ignore_expires=True) 
Example #16
Source File: NetUtils.py    From 12306 with MIT License 5 votes vote down vote up
def load_cookies(cookie_path):
        load_cookiejar = cookiejar.LWPCookieJar()
        load_cookiejar.load(cookie_path, ignore_discard=True, ignore_expires=True)
        load_cookies = requests.utils.dict_from_cookiejar(load_cookiejar)
        EasyHttp.__session.cookies = requests.utils.cookiejar_from_dict(load_cookies) 
Example #17
Source File: obs_operator.py    From openSUSE-release-tools with GNU General Public License v2.0 5 votes vote down vote up
def cookiejar_create(self, cookiejar_file, session):
        cookie_jar = LWPCookieJar(cookiejar_file.name)
        cookie_jar.set_cookie(Cookie(0, self.COOKIE_NAME, session,
            None, False,
            '', False, True,
            '/', True,
            True,
            None, None, None, None, {}))
        cookie_jar.save()
        cookiejar_file.flush() 
Example #18
Source File: api.py    From 115wangpan with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __init__(self, persistent=False,
                 cookies_filename=None, cookies_type='LWPCookieJar'):
        """
        :param bool auto_logout: whether to logout automatically when
            :class:`.API` object is destroyed

                                 .. deprecated:: 0.6.0
                                     Call :meth:`.API.logout` explicitly

        :param bool persistent: whether to use persistent session that stores
            cookies on disk
        :param str cookies_filename: path to the cookies file, use default
            path (`~/.115cookies`) if None
        :param str cookies_type: a string representing
            :class:`cookielib.FileCookieJar` subclass,
            `LWPCookieJar` (default) or `MozillaCookieJar`
        """
        self.persistent = persistent
        self.cookies_filename = cookies_filename
        self.cookies_type = cookies_type
        self.passport = None
        self.http = RequestHandler()
        self.logger = logging.getLogger(conf.LOGGING_API_LOGGER)
        # Cache attributes to decrease API hits
        self._user_id = None
        self._username = None
        self._signatures = {}
        self._upload_url = None
        self._lixian_timestamp = None
        self._root_directory = None
        self._downloads_directory = None
        self._receiver_directory = None
        self._torrents_directory = None
        self._task_count = None
        self._task_quota = None
        if self.persistent:
            self.load_cookies() 
Example #19
Source File: base.py    From zhihu-api with MIT License 5 votes vote down vote up
def __init__(self):
        super(Model, self).__init__()
        self.cookies = cookiejar.LWPCookieJar(filename=settings.COOKIES_FILE)
        try:
            self.cookies.load(ignore_discard=True)
        except FileNotFoundError:
            pass
        self.verify = False
        self.headers = settings.HEADERS 
Example #20
Source File: WeiboSuperCommentScrapy.py    From WeiboSuperSpider with Apache License 2.0 5 votes vote down vote up
def __init__(self, user, password, cookie_path):
        super(WeiboLogin, self).__init__()
        self.user = user
        self.password = password
        self.session = requests.Session()
        self.cookie_path = cookie_path
        # LWPCookieJar是python中管理cookie的工具,可以将cookie保存到文件,或者在文件中读取cookie数据到程序
        self.session.cookies = cookielib.LWPCookieJar(filename=self.cookie_path)
        self.index_url = "http://weibo.com/login.php"
        self.session.get(self.index_url, headers=headers, timeout=2)
        self.postdata = dict() 
Example #21
Source File: auth.py    From socli with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def login_required(func):
    """
    :desc: decorator method to check user's login status
    """

    @wraps(func)
    def wrapper(*args, **kwargs):
        """
        :desc: Wrapper to check if user is logged in, if the
               stored cookies contain cookie named `acct`
               and is not expired.
        """

        is_login = False
        resp = {'success': False, 'message': 'You are not logged in!'}

        if os.path.exists(COOKIES_FILE_PATH):
            cookiejar = LWPCookieJar(filename=COOKIES_FILE_PATH)
            cookiejar.load()

            for cookie in cookiejar:
                if cookie.name == 'acct':
                    expiry_time_obj = datetime.utcfromtimestamp(cookie.expires)

                    if datetime.now() > expiry_time_obj:
                        is_login = True

            if not is_login:
                os.remove(COOKIES_FILE_PATH)
            else:
                return func(*args, **kwargs)

        return resp

    return wrapper 
Example #22
Source File: auth.py    From socli with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_session():
    """
    :desc: Builds session from the saved cookies, if present.
           Otherwise, a new session is created.
    :return: requests.Session object
    """

    session = Session()

    if os.path.exists(COOKIES_FILE_PATH):
        session.cookies = LWPCookieJar(filename=COOKIES_FILE_PATH)
        session.cookies.load(ignore_discard=True, ignore_expires=True)

    return session 
Example #23
Source File: auth.py    From socli with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def login(email, password):
    """
    :desc: Logs a user in.
    :param: email - Email of the user - required
            password - Password of the user - required
    :return: `dict`
    """

    if email == '' or password == '':
        return {'success': False, 'message': 'Email/Password field left blank.'}

    resp = {'success': False}
    data = {'email': email, 'password': password}
    session = get_session()
    session.cookies = LWPCookieJar(filename=COOKIES_FILE_PATH)

    resp_obj = session.post(LOGIN_URL, data=data)

    if resp_obj.status_code == 200:
        if resp_obj.url == BASE_URL:
            session.cookies.save(ignore_expires=True, ignore_discard=True)
            resp['success'] = True
            resp['message'] = 'Successfully Logged In!'
        else:
            resp['message'] = 'Incorrect credentials'
    else:
        resp['message'] = 'Stackoverflow is probably down. Please try again.'

    return resp 
Example #24
Source File: Lgrup.py    From s-mbf with MIT License 5 votes vote down vote up
def main(self):
		cj = kuki('toket/kue.txt')
		cj.load()
		self.br.set_cookiejar(cj)
		for idg in self.id:
			self.br.open(f'https://mbasic.facebook.com/group/leave/?group_id={idg}&refid=18')
			self.br.select_form(nr=1)
			sub=self.br.submit().read()
			if 'Gabung dengan Grup' in str(sub) or 'Join Group' in str(sub):
				print(f'[+] {idg} - success leave the group')
			else:
				print(f'[-] {idg} - failed leave the group') 
Example #25
Source File: connection.py    From wiki-scripts with GNU General Public License v3.0 4 votes vote down vote up
def make_session(user_agent=DEFAULT_UA, ssl_verify=None, max_retries=0,
                     cookie_file=None, cookiejar=None,
                     http_user=None, http_password=None):
        """
        Creates a :py:class:`requests.Session` object for the connection.

        It is possible to save the session data by specifying either ``cookiejar``
        or ``cookie_file`` arguments. If ``cookiejar`` is present, ``cookie_file``
        is ignored.

        :param str user_agent: string sent as ``User-Agent`` header to the web server
        :param bool ssl_verify: if ``True``, the SSL certificate will be verified
        :param int max_retries:
            Maximum number of retries for each connection. Applies only to
            failed DNS lookups, socket connections and connection timeouts, never
            to requests where data has made it to the server.
        :param str cookie_file: path to a :py:class:`cookielib.FileCookieJar` file
        :param cookiejar: an existing :py:class:`cookielib.CookieJar` object
        :returns: :py:class:`requests.Session` object
        """
        session = requests.Session()

        if cookiejar is not None:
            session.cookies = cookiejar
        elif cookie_file is not None:
            session.cookies = cookielib.LWPCookieJar(cookie_file)
            try:
                session.cookies.load()
            except (cookielib.LoadError, FileNotFoundError):
                session.cookies.save()
                session.cookies.load()

        _auth = None
        if http_user is not None and http_password is not None:
            _auth = (http_user, http_password)

        session.headers.update({"user-agent": user_agent})
        session.auth = _auth
        session.params.update({"format": "json"})
        session.verify = ssl_verify

        # granular control over requests' retries: https://stackoverflow.com/a/35504626
        retries = Retry(total=max_retries, backoff_factor=1, status_forcelist=[500, 502, 503, 504])
        adapter = requests.adapters.HTTPAdapter(max_retries=retries)
        session.mount("https://", adapter)
        session.mount("http://", adapter)
        return session 
Example #26
Source File: client.py    From bugatsinho.github.io with GNU General Public License v3.0 4 votes vote down vote up
def cfcookie(netloc, ua, timeout):
    try:
        headers = {'User-Agent': ua}

        req = urllib2.Request(netloc, headers=headers)

        try:
            urllib2.urlopen(req, timeout=int(timeout))
        except urllib2.HTTPError as response:
            result = response.read(5242880)

        jschl = re.findall('name="jschl_vc" value="(.+?)"/>', result)[0]

        init = re.findall('setTimeout\(function\(\){\s*.*?.*:(.*?)};', result)[-1]

        builder = re.findall(r"challenge-form\'\);\s*(.*)a.v", result)[0]

        decryptVal = parseJSString(init)

        lines = builder.split(';')

        for line in lines:

            if len(line) > 0 and '=' in line:

                sections = line.split('=')
                line_val = parseJSString(sections[1])
                decryptVal = int(eval(str(decryptVal) + str(sections[0][-1]) + str(line_val)))

        answer = decryptVal + len(urlparse.urlparse(netloc).netloc)

        query = '%s/cdn-cgi/l/chk_jschl?jschl_vc=%s&jschl_answer=%s' % (netloc, jschl, answer)

        if 'type="hidden" name="pass"' in result:
            passval = re.findall('name="pass" value="(.*?)"', result)[0]
            query = '%s/cdn-cgi/l/chk_jschl?pass=%s&jschl_vc=%s&jschl_answer=%s' % (
                netloc, quote_plus(passval), jschl, answer
            )
            time.sleep(5)

        cookies = cookielib.LWPCookieJar()
        handlers = [urllib2.HTTPHandler(), urllib2.HTTPSHandler(), urllib2.HTTPCookieProcessor(cookies)]
        opener = urllib2.build_opener(*handlers)
        urllib2.install_opener(opener)

        try:
            req = urllib2.Request(query, headers=headers)
            urllib2.urlopen(req, timeout=int(timeout))
        except BaseException:
            pass

        cookie = '; '.join(['%s=%s' % (i.name, i.value) for i in cookies])

        return cookie
    except BaseException:
        pass 
Example #27
Source File: client.py    From script.module.openscrapers with GNU General Public License v3.0 4 votes vote down vote up
def get_cookie(self, netloc, ua, timeout):
		try:
			headers = {'User-Agent': ua}
			request = Request(netloc)
			_add_request_header(request, headers)

			try:
				response = urlopen(request, timeout=int(timeout))
			except HTTPError as response:
				result = response.read(5242880)
				try:
					encoding = response.info().getheader('Content-Encoding')
				except:
					encoding = None
				if encoding == 'gzip':
					result = gzip.GzipFile(fileobj=StringIO(result)).read()

			jschl = re.findall('name="jschl_vc" value="(.+?)"/>', result)[0]
			init = re.findall('setTimeout\(function\(\){\s*.*?.*:(.*?)};', result)[-1]
			builder = re.findall(r"challenge-form\'\);\s*(.*)a.v", result)[0]
			decryptVal = self.parseJSString(init)
			lines = builder.split(';')

			for line in lines:
				if len(line) > 0 and '=' in line:
					sections = line.split('=')
					line_val = self.parseJSString(sections[1])
					decryptVal = int(eval(str(decryptVal) + sections[0][-1] + str(line_val)))

			answer = decryptVal + len(urlparse(netloc).netloc)

			query = '%s/cdn-cgi/l/chk_jschl?jschl_vc=%s&jschl_answer=%s' % (netloc, jschl, answer)

			if 'type="hidden" name="pass"' in result:
				passval = re.findall('name="pass" value="(.*?)"', result)[0]
				query = '%s/cdn-cgi/l/chk_jschl?pass=%s&jschl_vc=%s&jschl_answer=%s' % (
					netloc, quote_plus(passval), jschl, answer)
				time.sleep(6)

			cookies = cookielib.LWPCookieJar()
			handlers = [HTTPHandler(), HTTPSHandler(), HTTPCookieProcessor(cookies)]
			opener = build_opener(*handlers)
			opener = install_opener(opener)

			try:
				request = Request(query)
				_add_request_header(request, headers)
				response = urlopen(request, timeout=int(timeout))
			except:
				pass

			cookie = '; '.join(['%s=%s' % (i.name, i.value) for i in cookies])

			if 'cf_clearance' in cookie:
				self.cookie = cookie
		except:
			pass 
Example #28
Source File: pyicloud_ic3.py    From icloud3 with MIT License 4 votes vote down vote up
def __init__(
        self,
        apple_id,
        password=None,
        cookie_directory=None,
        verify=True,
        client_id=None,
        with_family=True,
    ):
        if password is None:
            password = get_password_from_keyring(apple_id)

        self.data = {}
        self.client_id = client_id or str(uuid1()).upper()
        self.with_family = with_family
        self.user = {"apple_id": apple_id, "password": password}

        self.password_filter = PyiCloudPasswordFilter(password)
        LOGGER.addFilter(self.password_filter)

        self._base_login_url = f"{self.SETUP_ENDPOINT}/login"

        if cookie_directory:
            self._cookie_directory = path.expanduser(path.normpath(cookie_directory))
        else:
            self._cookie_directory = path.join(gettempdir(), "pyicloud")

        self.session = PyiCloudSession(self)
        self.session.verify = verify
        self.session.headers.update(
            {
                "Origin": self.HOME_ENDPOINT,
                "Referer": f"{self.HOME_ENDPOINT}/",
                "User-Agent": "Opera/9.52 (X11; Linux i686; U; en)",
            }
        )

        cookiejar_path = self._get_cookiejar_path()
        self.session.cookies = cookielib.LWPCookieJar(filename=cookiejar_path)
        if path.exists(cookiejar_path):
            try:
                self.session.cookies.load()
                LOGGER.debug(f"Read cookies from {cookiejar_path}")
            except:  # pylint: disable=bare-except
                # Most likely a pickled cookiejar from earlier versions.
                # The cookiejar will get replaced with a valid one after
                # successful authentication.
                LOGGER.warning(f"Failed to read cookiejar {cookiejar_path}")

        self.params = {
            "clientBuildNumber": "17DHotfix5",
            "clientMasteringNumber": "17DHotfix5",
            "ckjsBuildVersion": "17DProjectDev77",
            "ckjsVersion": "2.0.5",
            "clientId": self.client_id,
        }

        self.authenticate()

        self._files = None
        self._photos = None