mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Warn users with ProactorEventLoop about proxy issues (#1337)
This commit is contained in:
parent
b985dcd248
commit
99d4001db6
|
@ -3,6 +3,7 @@ import asyncio
|
||||||
import collections
|
import collections
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
@ -251,6 +252,30 @@ class TelegramBaseClient(abc.ABC):
|
||||||
self.api_id = int(api_id)
|
self.api_id = int(api_id)
|
||||||
self.api_hash = api_hash
|
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._request_retries = request_retries
|
||||||
self._connection_retries = connection_retries
|
self._connection_retries = connection_retries
|
||||||
self._retry_delay = retry_delay or 0
|
self._retry_delay = retry_delay or 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user