From 99d4001db6c14e86822785e93f96608f2e803d2f Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 5 Dec 2019 11:25:48 +0100 Subject: [PATCH] Warn users with ProactorEventLoop about proxy issues (#1337) --- telethon/client/telegrambaseclient.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index b05b76a9..ca106271 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -3,6 +3,7 @@ import asyncio import collections import logging import platform +import sys import time import typing @@ -251,6 +252,30 @@ class TelegramBaseClient(abc.ABC): self.api_id = int(api_id) self.api_hash = api_hash + # Python 3.8 changed the default event loop on Windows, + # which is now ProactorEventLoop and has some issues with + # the current proxy implementation (it lacks sock_connect). + # + # If we're using ProactorEventLoop and have a proxy, bail out + # early asking the user to consider changing the event loop + # TODO until we apply a different fix to this. + # + # See https://github.com/LonamiWebs/Telethon/issues/1337 for details. + proactor = getattr(asyncio, 'ProactorEventLoop', None) + if (proxy is not None + and proactor is not None + and sys.version_info >= (3, 8) + and isinstance(self._loop, proactor)): + raise TypeError( + 'Cannot use the event loop of type {} with a proxy.\n\n' + 'Change the event loop in use to use proxies:\n' + '# https://github.com/LonamiWebs/Telethon/issues/1337\n' + 'import asyncio\n' + 'asyncio.set_event_loop(asyncio.SelectorEventLoop())'.format( + self._loop.__class__.__name__ + ) + ) + self._request_retries = request_retries self._connection_retries = connection_retries self._retry_delay = retry_delay or 0