From 64c27e568a4d4602c43c36b5d2f83f873f1a44be Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Wed, 5 Oct 2022 19:44:00 +0400 Subject: [PATCH] Passing custom parameters to CloudScraper --- python_aternos/atconnect.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/python_aternos/atconnect.py b/python_aternos/atconnect.py index 3b4a70e..34d0f2b 100644 --- a/python_aternos/atconnect.py +++ b/python_aternos/atconnect.py @@ -30,10 +30,34 @@ class AternosConnect: def __init__(self) -> None: - self.session = CloudScraper() + self.cf_init = partial(CloudScraper) + self.session = self.cf_init() self.sec = '' self.token = '' + def add_args(self, **kwargs) -> None: + + """Pass arguments to + CloudScarper session object __init__ + + Args: + **kwargs: Keyword arguments + """ + + self.cf_init = partial(CloudScraper, **kwargs) + self.refresh_session() + + def refresh_session(self) -> None: + + """Creates a new CloudScraper + session object and copies all cookies. + Required for bypassing Cloudflare""" + + old_cookies = self.session.cookies + self.session = self.cf_init() + self.session.cookies.update(old_cookies) + del old_cookies + def parse_token(self) -> str: """Parses Aternos ajax token that @@ -143,10 +167,7 @@ class AternosConnect: if retry <= 0: raise CloudflareError('Unable to bypass Cloudflare protection') - old_cookies = self.session.cookies - self.session = CloudScraper() - self.session.cookies.update(old_cookies) - del old_cookies + self.refresh_session() params = params or {} data = data or {}