From: Harmon Date: Tue, 23 Nov 2021 13:41:24 +0000 (-0600) Subject: Initialize Stream.session within Stream.__init__ X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=80adf5b2cc861ab6837ae03052378719e694bebc;p=tweepy.git Initialize Stream.session within Stream.__init__ Update the user agent based on Stream.user_agent even if Stream.session is already initialized --- diff --git a/tweepy/streaming.py b/tweepy/streaming.py index f18b28f..1bbc2f9 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -58,7 +58,7 @@ class Stream: ---------- running : bool Whether there's currently a stream running - session : Optional[:class:`requests.Session`] + session : :class:`requests.Session` Requests Session used to connect to the stream thread : Optional[:class:`threading.Thread`] Thread used to run the stream @@ -80,7 +80,7 @@ class Stream: self.verify = verify self.running = False - self.session = None + self.session = requests.Session() self.thread = None self.user_agent = ( f"Python/{python_version()} " @@ -103,9 +103,7 @@ class Stream: auth = OAuth1(self.consumer_key, self.consumer_secret, self.access_token, self.access_token_secret) - if self.session is None: - self.session = requests.Session() - self.session.headers["User-Agent"] = self.user_agent + self.session.headers["User-Agent"] = self.user_agent url = f"https://stream.twitter.com/1.1/{endpoint}.json"