Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the same proxy Telethon can not connect Telegram but Pyrogram work #4505

Open
3 tasks done
hyperbolic-c opened this issue Nov 9, 2024 · 1 comment
Open
3 tasks done

Comments

@hyperbolic-c
Copy link

hyperbolic-c commented Nov 9, 2024

Code that causes the issue

from telethon import TelegramClient, events, types
from telethon.sessions import StringSession

session = StringSession()
client = TelegramClient(session, api_id, api_hash, proxy=teleProxy)

client.start(phone=phone_number)
async def main():
    me = await client.get_me()
    print(me.stringify())
with client:
    client.loop.run_until_complete(main())

Expected behavior

I am going to connect Telegram using Telethon with a proxy in a .py file, but always get a error: ConnectionError: Connection to Telegram failed 5 time(s). When I used Jupyter notebook it works. Then I try to use Pyrogram with the same proxy, it can connect to Telegram !!! And my desktop Telegram work, too. So it is just Telethon get a error.

Actual behavior

Attempt 4 at connecting failed: ProxyConnectionError: Error connecting to HTTP proxy 127.0.0.1:7897: [WinError 10061] 
Attempt 5 at connecting failed: ProxyConnectionError: Error connecting to HTTP proxy 127.0.0.1:7897: [WinError 10061] 
Attempt 6 at connecting failed: ProxyConnectionError: Error connecting to HTTP proxy 127.0.0.1:7897: [WinError 10061] 
Automatic reconnection failed 5 time(s)

Traceback

No response

Telethon version

1.37

Python version

3.11

Operating system (including distribution name and version)

Windows 11

Other details

No response

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.
@ebrahimrb
Copy link

ebrahimrb commented Nov 27, 2024

Hi ,
Just install python_socks ,
I had the same issue. This library uses two libraries for connecting to a proxy. When python_socks is installed, it uses that, and everything works fine without any problems. However, when it uses the other library, socks, it faces issues, and the proxy isn't applied—it gets bypassed. I couldn’t figure out why this happens, as my knowledge isn’t deep enough to understand the code at that level.

pip install python_socks

Read This : https://docs.telethon.dev/en/stable/basic/signing-in.html#signing-in-behind-a-proxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants