Telethon: How to use proxy in telethon?

Created on 4 Sep 2017  路  10Comments  路  Source: LonamiWebs/Telethon

import sys
import socks

from telethon import TelegramClient
from telethon.tl.types import InputPhoneContact
from telethon.tl.functions.contacts import ImportContactsRequest
from telethon.errors import FloodWaitError, RPCError

api_id = 0  # a valid api_id
api_hash = ''  # a valid api_hash

w = input('Which: ')

host = 8.8.8.8  # a valid host
port = 80  # a valid port
proxy = (socks.SOCKS5, host, port)

client = TelegramClient('N{}'.format(w), api_id, api_hash, proxy)
client.connect()

Above code doesn't work. what is the problem???

Most helpful comment

What worked?

All 10 comments

what is the problem???

No idea. Why doesn't it work? What's the problem? Have you tried connecting without a socket? Does that work? Can you confirm that said "valid host and port" work correctly somehow else?

valid host and port works with requests and opens a URL successfully. and doesn't work
without proxy, it's OK

Could you at least provide a traceback of where it stops working, or what the error is?

socks.GeneralProxyError: Socket error: timed out
This is the error what happens
It happens in 'client.connect()' line

It Worked successfully!!! Thanks

What worked?

with another proxy:))

Okay, we can close the issue then.

i got timeout too. [Errno Connection to Telegram failed %d time(s)]

with another proxy:))

which proxy?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aminhyper picture aminhyper  路  3Comments

iranpak picture iranpak  路  3Comments

Lerbytech picture Lerbytech  路  5Comments

chri1389 picture chri1389  路  6Comments

Fleyderer picture Fleyderer  路  3Comments