Skip to content

Commit

Permalink
Warn users with ProactorEventLoop about proxy issues (LonamiWebs#1337)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonami committed Dec 5, 2019
1 parent b985dcd commit 99d4001
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions telethon/client/telegrambaseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@
import collections
import logging
import platform
import sys
import time
import typing

Expand Down Expand Up @@ -251,6 252,30 @@ def __missing__(self, key):
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
Expand Down

0 comments on commit 99d4001

Please sign in to comment.