[Python] Proxy works in checker tools but fails in Python (Telethon) with "GeneralProxyError:...

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to connect to Telegram using Telethon with a SOCKS5 proxy, but I keep getting GeneralProxyError: Socket error: timed out after multiple attempts.

    The proxy is verified working in online proxy checkers, but in Python (Telethon), it fails with:

    Attempt 1 at connecting failed: GeneralProxyError: Socket error: timed out


    CODE:

    from telethon.sync import TelegramClient
    from telethon.sessions import StringSession
    from telethon.network.connection.tcpabridged import ConnectionTcpAbridged
    from telethon import functions, types


    api_id = 1234
    api_hash = '12345'


    proxy = {
    'proxy_type': 'socks5', # (mandatory)
    'addr': '194.32.229.199', # (mandatory)
    'port': 1050, # (mandatory)
    'username': 'user', # (optional)
    'password': 'pass', # (optional)
    'rdns': True # (optional)
    }


    with TelegramClient(
    StringSession(), # Сохраняет сессию для повторного входа
    api_id,
    api_hash,
    proxy=proxy,
    connection=ConnectionTcpAbridged # Улучшает работу с прокси
    ) as client:

    me = client.get_me()
    print(f"Успешная авторизация через прокси!")
    print(f"ID: {me.id}")
    print(f"Имя: {me.first_name}")
    print(f"Username: @{me.username}")

    print("\nСтрока сессии для повторного входа:")
    print(client.session.save())

    Continue reading...

Compartilhe esta Página