Pass headers explicitly in Stream.filter
authorHarmon <Harmon758@gmail.com>
Mon, 25 Jan 2021 18:51:36 +0000 (12:51 -0600)
committerHarmon <Harmon758@gmail.com>
Mon, 25 Jan 2021 18:51:50 +0000 (12:51 -0600)
Add and use Stream._connect headers parameter

tweepy/streaming.py

index 80438eba59e65e300cbafff387fb54ec598b97c6..153bed4eb91afcfbfcca5eef2c979c2bbf729289 100644 (file)
@@ -45,7 +45,7 @@ class Stream:
         self.session = None
         self.thread = None
 
-    def _connect(self, method, endpoint, params=None, body=None):
+    def _connect(self, method, endpoint, params=None, headers=None, body=None):
         self.running = True
 
         if self.session is None:
@@ -69,7 +69,7 @@ class Stream:
             while self.running and error_count <= self.max_retries:
                 try:
                     with self.session.request(
-                        method, url, params=params, data=body,
+                        method, url, params=params, headers=headers, data=body,
                         timeout=stall_timeout, stream=True, auth=auth,
                         verify=self.verify, proxies=self.proxies
                     ) as resp:
@@ -143,6 +143,7 @@ class Stream:
 
         method = 'POST'
         endpoint = 'statuses/filter'
+        headers = {"Content-Type": "application/x-www-form-urlencoded"}
 
         body = {}
         if follow:
@@ -162,9 +163,10 @@ class Stream:
             body['stall_warnings'] = stall_warnings
 
         if threaded:
-            return self._threaded_connect(method, endpoint, body=body)
+            return self._threaded_connect(method, endpoint, headers=headers,
+                                          body=body)
         else:
-            self._connect(method, endpoint, body=body)
+            self._connect(method, endpoint, headers=headers, body=body)
 
     def sample(self, *, languages=None, stall_warnings=False, threaded=False):
         if self.running: