Hi everyone.
Running python64 3.8 under Windows 10
proxy = (socks.SOCKS5, '1.1.1.1', 1111)
client = TelegramClient(sessions_folder + phone, api_id, api_hash, proxy=proxy)
client.connect()
I am able to connect despite using not valid proxy, hence the proxy is not used. Under python 3.7 i get expected "can't connect" response.
I'm having similar issue: client ignores proxy settings, it's trying to connect to servers directly.
3.8 32bit
I did some research. ProactorEventLoop causing the proxy to be ignored.
In python 3.8 changelog:
on Windows, the default asyncio event loop is now ProactorEventLoop
Setting event loop to SelectorEventLoop fixes the issue.
asyncio.set_event_loop(asyncio.SelectorEventLoop())
Do you know what the implications of that are, and what was the full traceback previously?
If i understood correctly ProactorEventLoop is missing 'sock_connect' method used here
Thanks for investigating, until a proper fix is released, this is better than nothing. Force pushing another commit with a typo fixed.
That fix isnt enough. see my comment on the commit
It's not a fix, it's just a way to warn users about a possible workaround.
i know. but it wont warn the users on 3.7. see my comment
Users on 3.7 with ProactorLoop will also lack the method we need, won't they? Or was it just removed in 3.8?
Yeah, they'll lack it too
But look:
if (proxy is not None
and proactor is not None
and sys.version_info >= (3, 8)
and isinstance(self._loop, proactor)):
The warning wont show on 3.7, but its possible to set event loop manually on 3.7, to fix subprocesses on windows (my code does)
Oh, understood, that makes sense. So we should simply remove the sys.version_info check, you say?
Yes
asyncio.set_event_loop(asyncio.SelectorEventLoop())
where should I put this? I put this in my telegram client but it still wont connect. So im on 3.7 =(
ok. I should put it not in def main, but right after #import statements
@ism
_Running python64 3.8 under Windows 10_
_Under python 3.7 I get expected "can't connect" response._proxy = (socks.SOCKS5, '1.1.1.1', 1111) client = TelegramClient(sessions_folder + phone, api_id, api_hash, proxy=proxy)
@lokkiser
_python32 3.8 - similar issue: client ignores proxy settings, it's trying to connect to servers directly_
@DaveScream
_I put this in my telegram client but it still wont connect. So im on 3.7 =(_
@penn5, @Lonami
Windows users might have fails due WindowsSelectorEventLoopPolicy
import socks
client = TelegramClient(session_name, api_id, api_hash, proxy=(socks.SOCKS5, 'SOCKS5_PROXY_IP', SOCKS5_PROXY_PORT, True, 'SOCKS5_PROXY_USERNAME', 'SOCKS5_PROXY_PASSWORD'))
@x0x8x that's an issue. It does work when it should not. :-)
Most helpful comment
I did some research. ProactorEventLoop causing the proxy to be ignored.
In python 3.8 changelog:
Setting event loop to SelectorEventLoop fixes the issue.
asyncio.set_event_loop(asyncio.SelectorEventLoop())