Replace Stream.auth with parameters and attributes for each credential
authorHarmon <Harmon758@gmail.com>
Sat, 23 Jan 2021 16:32:41 +0000 (10:32 -0600)
committerHarmon <Harmon758@gmail.com>
Sat, 23 Jan 2021 16:32:41 +0000 (10:32 -0600)
Replace Stream.auth with Stream.consumer_key, Stream.consumer_secret, Stream.access_token, Stream.access_token_secret

tweepy/streaming.py

index 1d9f51f2491d895d9baaf17629425362d7595590..8738ae60ca3657c3c8480aa51a6b8ad615c80276 100644 (file)
@@ -11,6 +11,7 @@ from threading import Thread
 from time import sleep
 
 import requests
+from requests_oauthlib import OAuth1
 import urllib3
 
 from tweepy.api import API
@@ -120,8 +121,12 @@ class StreamListener:
 
 class Stream:
 
-    def __init__(self, auth, listener, **options):
-        self.auth = auth
+    def __init__(self, consumer_key, consumer_secret, access_token,
+                 access_token_secret, listener, **options):
+        self.consumer_key = consumer_key
+        self.consumer_secret = consumer_secret
+        self.access_token = access_token
+        self.access_token_secret = access_token_secret
         self.listener = listener
         self.running = False
         self.daemon = options.get("daemon", False)
@@ -147,8 +152,12 @@ class Stream:
     def _run(self, endpoint, params=None, body=None):
         if self.session is None:
             self.session = requests.Session()
+
         url = f"https://stream.twitter.com/{STREAM_VERSION}/{endpoint}.json"
 
+        auth = OAuth1(self.consumer_key, self.consumer_secret,
+                      self.access_token, self.access_token_secret)
+
         error_count = 0
         # https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/connecting
         network_error_wait = network_error_wait_step = 0.25
@@ -163,7 +172,6 @@ class Stream:
                     if error_count > self.retry_count:
                         break
                 try:
-                    auth = self.auth.apply_auth()
                     with self.session.request(
                         'POST', url, params=params, data=body,
                         timeout=self.timeout, stream=True, auth=auth,