async def _connect(
self, method, url, params=None, headers=None, body=None,
- oauth_client=None
+ oauth_client=None, timeout=20
):
error_count = 0
# https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/connecting
# https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/integrate/handling-disconnections
# https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/integrate/handling-disconnections
- stall_timeout = 90
network_error_wait = network_error_wait_step = 0.25
network_error_wait_max = 16
http_error_wait = http_error_wait_start = 5
if self.session is None or self.session.closed:
self.session = aiohttp.ClientSession(
- timeout=aiohttp.ClientTimeout(sock_read=stall_timeout)
+ timeout=aiohttp.ClientTimeout(sock_read=timeout)
)
self.session.headers["User-Agent"] = self.user_agent
url = f"https://stream.twitter.com/1.1/{endpoint}.json"
url = str(URL(url).with_query(sorted(params.items())))
await super()._connect(
- method, url, headers=headers, body=body, oauth_client=oauth_client
+ method, url, headers=headers, body=body, oauth_client=oauth_client,
+ timeout=90
)
def filter(self, *, follow=None, track=None, locations=None,
f"Tweepy/{tweepy.__version__}"
)
- def _connect(self, method, url, auth=None, params=None, headers=None,
- body=None):
+ def _connect(
+ self, method, url, auth=None, params=None, headers=None, body=None,
+ timeout=20
+ ):
self.running = True
error_count = 0
# https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/connecting
# https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/integrate/handling-disconnections
# https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/integrate/handling-disconnections
- stall_timeout = 90
network_error_wait = network_error_wait_step = 0.25
network_error_wait_max = 16
http_error_wait = http_error_wait_start = 5
try:
with self.session.request(
method, url, params=params, headers=headers, data=body,
- timeout=stall_timeout, stream=True, auth=auth,
+ timeout=timeout, stream=True, auth=auth,
verify=self.verify, proxies=self.proxies
) as resp:
if resp.status_code == 200:
auth = OAuth1(self.consumer_key, self.consumer_secret,
self.access_token, self.access_token_secret)
url = f"https://stream.twitter.com/1.1/{endpoint}.json"
- super()._connect(method, url, auth=auth, **kwargs)
+ super()._connect(method, url, auth=auth, timeout=90, **kwargs)
def filter(self, *, follow=None, track=None, locations=None,
filter_level=None, languages=None, stall_warnings=False,