Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

wait_s error #67

Open
kunokareal opened this issue Jun 5, 2024 · 1 comment
Open

wait_s error #67

kunokareal opened this issue Jun 5, 2024 · 1 comment

Comments

@kunokareal
Copy link

since recently sometimes when logging in it randomly returns an object containing wait_s field, in which case an "app is overloaded" screen is shown with a timer.

i'm too lazy to open a proper pr, so here's the gist:

diff --git a/bot/core/tapper.py b/bot/core/tapper.py
index 3e8c258..d8bffa6 100644
--- a/bot/core/tapper.py
+++ b/bot/core/tapper.py
@@ -97,6 +97,12 @@ class Tapper:
             response.raise_for_status()
 
             response_json = await response.json()
+            wait_s = response_json.get('wait_s')
+            if wait_s:
+                logger.error(f"{self.session_name} | App overloaded, waiting for: {wait_s}")
+                await asyncio.sleep(delay=wait_s)
+                return self.login(http_client, tg_web_data)
+
             chq = response_json.get('chq')
             if chq:
                 chq_result = extract_chq(chq=chq)
@NLegal
Copy link

NLegal commented Jun 5, 2024

Adjusted a bit:

    async def login(self, http_client: aiohttp.ClientSession, tg_web_data: str) -> tuple[dict[str], str]:
        response_text = ''
        try:
            response = await http_client.post(url='https://api.tapswap.ai/api/account/login',
                                              json={"init_data": tg_web_data, "referrer": ""})
            response_text = await response.text()
            response.raise_for_status()

            response_json = await response.json()

            wait_s = response_json.get('wait_s')
            if wait_s:
                logger.error(f"{self.session_name} | App overloaded, waiting for: {wait_s}")
                await asyncio.sleep(delay=wait_s)
                return await self.login(http_client, tg_web_data)

            chq = response_json.get('chq')
            if chq:
                chq_result = extract_chq(chq=chq)

                response = await http_client.post(url='https://api.tapswap.ai/api/account/login',
                                                json={"chr": chq_result, "init_data": tg_web_data, "referrer": ""})
                response_text = await response.text()
                response.raise_for_status()

                response_json = await response.json()


            access_token = response_json['access_token']
            profile_data = response_json

            return profile_data, access_token
        except Exception as error:
            logger.error(f"{self.session_name} | Unknown error while getting Access Token: {error} | "
                         f"Response text: {escape_html(response_text)[:128]}...")
            await asyncio.sleep(delay=3)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants