Log streaming connection error exceptions
authorHarmon <Harmon758@gmail.com>
Sat, 29 Oct 2022 05:30:27 +0000 (00:30 -0500)
committerHarmon <Harmon758@gmail.com>
Sat, 29 Oct 2022 05:30:27 +0000 (00:30 -0500)
tweepy/asynchronous/streaming.py
tweepy/streaming.py

index c413a534622fa7e819e58ba9ce9c4dff3f5c78a7..1d520e20e0670ef785244bdd216d7d51051e8a30 100644 (file)
@@ -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)
 
index 7e77e17bf96c81a466533f9d32a24f677561a0ab..efa56f22fba3e713929eec8bd60be452612f7758 100644 (file)
@@ -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)