From: Harmon Date: Sat, 29 Oct 2022 05:30:27 +0000 (-0500) Subject: Log streaming connection error exceptions X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b7f02c60b252b747e16d84ccfedb275d85720439;p=tweepy.git Log streaming connection error exceptions --- diff --git a/tweepy/asynchronous/streaming.py b/tweepy/asynchronous/streaming.py index c413a53..1d520e2 100644 --- a/tweepy/asynchronous/streaming.py +++ b/tweepy/asynchronous/streaming.py @@ -7,6 +7,7 @@ import json import logging from math import inf from platform import python_version +import traceback import aiohttp from oauthlib.oauth1 import Client as OAuthClient @@ -111,6 +112,16 @@ class AsyncBaseStream: except (aiohttp.ClientConnectionError, aiohttp.ClientPayloadError) as e: await self.on_connection_error() + # The error text is logged here instead of in + # on_connection_error to keep on_connection_error + # backwards-compatible. In a future version, the error + # should be passed to on_connection_error. + log.error( + "Connection error: %s", + "".join( + traceback.format_exception_only(type(e), e) + ).rstrip() + ) await asyncio.sleep(network_error_wait) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 7e77e17..efa56f2 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -10,6 +10,7 @@ import logging from math import inf from platform import python_version import ssl +import traceback from threading import Thread from time import sleep from typing import NamedTuple @@ -134,6 +135,16 @@ class BaseStream: self.on_connection_error() if not self.running: break + # The error text is logged here instead of in + # on_connection_error to keep on_connection_error + # backwards-compatible. In a future version, the error + # should be passed to on_connection_error. + log.error( + "Connection error: %s", + "".join( + traceback.format_exception_only(type(exc), exc) + ).rstrip() + ) sleep(network_error_wait)