Skip to content

Commit

Permalink
Initialize Stream.session within Stream.__init__
Browse files Browse the repository at this point in the history
Update the user agent based on Stream.user_agent even if Stream.session is already initialized
  • Loading branch information
Harmon758 committed Feb 20, 2022
1 parent 4e2997e commit 80adf5b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions tweepy/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -80,7 +80,7 @@ def __init__(self, consumer_key, consumer_secret, access_token,
self.verify = verify

self.running = False
self.session = None
self.session = requests.Session()
self.thread = None
self.user_agent = (
f"Python/{python_version()} "
Expand All @@ -103,9 +103,7 @@ def _connect(self, method, endpoint, params=None, headers=None, body=None):
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"

Expand Down

0 comments on commit 80adf5b

Please sign in to comment.