mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Except IOError and not ConnectionError
PySocks' errors do not subclass ConnectionError so the library was unnecessarily logging them as unexpected, when any IOError was actually expected.
This commit is contained in:
parent
c902428af1
commit
7523869875
|
@ -144,7 +144,7 @@ class Connection(abc.ABC):
|
|||
except asyncio.CancelledError:
|
||||
pass
|
||||
except Exception as e:
|
||||
if isinstance(e, ConnectionError):
|
||||
if isinstance(e, IOError):
|
||||
self._log.info('The server closed the connection while sending')
|
||||
else:
|
||||
self._log.exception('Unexpected exception in the send loop')
|
||||
|
@ -161,7 +161,7 @@ class Connection(abc.ABC):
|
|||
except asyncio.CancelledError:
|
||||
break
|
||||
except Exception as e:
|
||||
if isinstance(e, (ConnectionError, asyncio.IncompleteReadError)):
|
||||
if isinstance(e, (IOError, asyncio.IncompleteReadError)):
|
||||
msg = 'The server closed the connection'
|
||||
self._log.info(msg)
|
||||
elif isinstance(e, InvalidChecksumError):
|
||||
|
|
|
@ -198,7 +198,7 @@ class MTProtoSender:
|
|||
try:
|
||||
self._log.debug('Connection attempt {}...'.format(attempt))
|
||||
await self._connection.connect(timeout=self._connect_timeout)
|
||||
except (ConnectionError, asyncio.TimeoutError) as e:
|
||||
except (IOError, asyncio.TimeoutError) as e:
|
||||
self._log.warning('Attempt {} at connecting failed: {}: {}'
|
||||
.format(attempt, type(e).__name__, e))
|
||||
await asyncio.sleep(self._delay)
|
||||
|
@ -308,7 +308,7 @@ class MTProtoSender:
|
|||
for attempt in retry_range(retries):
|
||||
try:
|
||||
await self._connect()
|
||||
except (ConnectionError, asyncio.TimeoutError) as e:
|
||||
except (IOError, asyncio.TimeoutError) as e:
|
||||
self._log.info('Failed reconnection attempt %d with %s',
|
||||
attempt, e.__class__.__name__)
|
||||
|
||||
|
@ -377,7 +377,7 @@ class MTProtoSender:
|
|||
data = self._state.encrypt_message_data(data)
|
||||
try:
|
||||
await self._connection.send(data)
|
||||
except ConnectionError:
|
||||
except IOError:
|
||||
self._log.info('Connection closed while sending data')
|
||||
self._start_reconnect()
|
||||
return
|
||||
|
@ -404,7 +404,7 @@ class MTProtoSender:
|
|||
self._log.debug('Receiving items from the network...')
|
||||
try:
|
||||
body = await self._connection.recv()
|
||||
except ConnectionError:
|
||||
except IOError:
|
||||
self._log.info('Connection closed while receiving data')
|
||||
self._start_reconnect()
|
||||
return
|
||||
|
|
|
@ -115,7 +115,10 @@ class InteractiveTelegramClient(TelegramClient):
|
|||
print('Connecting to Telegram servers...')
|
||||
try:
|
||||
loop.run_until_complete(self.connect())
|
||||
except ConnectionError:
|
||||
except IOError:
|
||||
# We handle IOError and not ConnectionError because
|
||||
# PySocks' errors do not subclass ConnectionError
|
||||
# (so this will work with and without proxies).
|
||||
print('Initial connection failed. Retrying...')
|
||||
loop.run_until_complete(self.connect())
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user