import socks
from telethon import TelegramClient, sync
client = TelegramClient('canadatest2', init.api_id, init.api_hash, proxy=(socks.SOCKS5,'161.35.70.249', 1080))
...
OS Win 10 LTSC 1809, Python 3.8
Telegram detect real IP through proxy. Proxy work. It show change lang in confirm message.

same problem. did you solve the problem?
No. I'm wait. I think that problem in socks lib, I not found place in telethon code where it send real ip address.
I have no interest in dealing with proxies myself, so I'll add a help wanted label to see if people want to help out. I can provide assistance if anyone needs help understanding the bits of the library required to solve this.
No. I'm wait. I think that problem in socks lib, I not found place in telethon code where it send real ip address.
Could you show it?
@Lonami who wrote the part of the code related to the proxy? maybe the one who wrote and will help
I don't remember, and IIRC I'm the one who modified the code over time to adapt it to use asyncio.
I don't remember, and IIRC I'm the one who modified the code over time to adapt it to use
asyncio.
show you the stack trace? and maybe this will help you understand what the problem is
What stack trace? Isn't the main problem here that the proxy is seemingly ignored?
client = TelegramClient("anon", api_id, api_hash,
connection=connection.http.ConnectionHttp,
proxy=(socks.HTTP, 'ip', port, "log", "pass"))
...
stack trace if using socks.HTTP and connection.http.ConnectionHttp
2020-09-24 10:26:01,536 INFO: Connecting to 149.154.167.51:443/Http...
2020-09-24 10:26:01,655 WARNING: Attempt 1 at connecting failed: FileNotFoundError: [Errno 2] No such file or directory
2020-09-24 10:26:12,717 WARNING: Attempt 2 at connecting failed: timeout: _ssl.c:1106: The handshake operation timed out
2020-09-24 10:26:13,836 WARNING: Attempt 3 at connecting failed: OSError: [Errno 0] Error
2020-09-24 10:26:24,902 WARNING: Attempt 4 at connecting failed: timeout: _ssl.c:1106: The handshake operation timed out
2020-09-24 10:26:26,019 WARNING: Attempt 5 at connecting failed: OSError: [Errno 0] Error
2020-09-24 10:26:27,143 WARNING: Attempt 6 at connecting failed: OSError: [Errno 0] Error
Traceback (most recent call last):
File "D:/..", line 166, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "Programs\Python\Python38-32\lib\asyncio\base_events.py", line 616, in run_until_complete
return future.result()
File "D:/..", line 148, in main
await client.start(phone=phone,
File "Programs\Python\Python38-32\lib\site-packages\telethon\client\auth.py", line 139, in _start
await self.connect()
File "CPrograms\Python\Python38-32\lib\site-packages\telethon\client\telegrambaseclient.py", line 480, in connect
if not await self._sender.connect(self._connection(
File "Programs\Python\Python38-32\lib\site-packages\telethon\network\mtprotosender.py", line 125, in connect
await self._connect()
File "Programs\Python\Python38-32\lib\site-packages\telethon\network\mtprotosender.py", line 250, in _connect
raise ConnectionError('Connection to Telegram failed {} time(s)'.format(self._retries))
ConnectionError: Connection to Telegram failed 5 time(s)
if used without ConnectionHttp or connection.tcpfull.ConnectionTcpFull then it ignores the proxy.
maybe I'm doing something wrong? I searched for and tried different approaches for a very long time - unsuccessfully
I did write the proxy part. https://github.com/LonamiWebs/Telethon/pull/37/files It seems they are still alive here https://github.com/LonamiWebs/Telethon/blob/master/telethon/network/connection/connection.py#L54
However, I can't reproduce this issue. I've tried socks.SOCKS5 and socks.HTTP proxy. Both of them work well.
Versions:
Telethon git: c864ef, though I think v1.16.4 should be the same
pysocks: 1.7.1
Test code:
import socks
from telethon import TelegramClient
API_ID = 1
API_HASH = '1'
# with TelegramClient('me', API_ID, API_HASH, proxy=(socks.SOCKS5, '127.0.0.1', 8088)) as client:
with TelegramClient('me', API_ID, API_HASH, proxy=(socks.HTTP, '127.0.0.1', 8089)) as client:
client.loop.run_until_complete(client.send_message('me', 'Hello, myself!'))
The only difference I can tell is that your devices are "Desktop" and mines are "Unknown device".

solution: https://github.com/LonamiWebs/Telethon/issues/1337#issuecomment-560490965
import asyncio
import socks
from telethon import TelegramClient
from telethon.tl.functions.account import GetAuthorizationsRequest
proxy = (socks.SOCKS5, proxy_ip, int(proxy_port), True, proxy_login, proxy_password)
async def auth():
client = TelegramClient(
session=phone,
api_id=api_id,
api_hash=api_hash,
proxy=proxy
)
await client.connect()
sessions = await client(GetAuthorizationsRequest())
print(sessions)
if __name__ == '__main__':
asyncio.set_event_loop(asyncio.SelectorEventLoop())
loop = asyncio.get_event_loop()
loop.run_until_complete(auth())
Try it
Most helpful comment
I did write the proxy part. https://github.com/LonamiWebs/Telethon/pull/37/files It seems they are still alive here https://github.com/LonamiWebs/Telethon/blob/master/telethon/network/connection/connection.py#L54
However, I can't reproduce this issue. I've tried socks.SOCKS5 and socks.HTTP proxy. Both of them work well.
Versions:
Telethon git: c864ef, though I think v1.16.4 should be the same
pysocks: 1.7.1
Test code:
The only difference I can tell is that your devices are "Desktop" and mines are "Unknown device".
