(http_client: ClientSession)
| 7 | from bot.utils.logger import logger |
| 8 | |
| 9 | async def check_proxy(http_client: ClientSession) -> str | None: |
| 10 | try: |
| 11 | response = await http_client.get(url='https://api.ipify.org?format=json', timeout=ClientTimeout(5)) |
| 12 | data = await response.json() |
| 13 | if data and data.get('ip'): |
| 14 | return data.get('ip') |
| 15 | except (ConnectionRefusedError, ClientProxyConnectionError, CancelledError): |
| 16 | logger.trace(f"Proxy not available") |
| 17 | except ProxyError as e: |
| 18 | logger.error(f"The proxy type may be incorrect! Error: {type(e).__name__}: {e}") |
| 19 | except Exception as e: |
| 20 | logger.error(f"{traceback.format_exc()}") |
| 21 | |
| 22 | |
| 23 | async def wait_proxy(http_client: ClientSession, time_between_checks_sec: int = 5) -> str | None: |
no test coverage detected