Open kunokareal opened 3 months ago
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)
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: