Stop overriding default requests Session headers in APIMethod
authorHarmon <Harmon758@gmail.com>
Thu, 28 Jan 2021 17:42:03 +0000 (11:42 -0600)
committerHarmon <Harmon758@gmail.com>
Thu, 28 Jan 2021 17:42:03 +0000 (11:42 -0600)
Pass custom headers to Session.request instead

tweepy/binder.py

index 68cc66df9c02c4df2b8a1874dccd017839777921..2cfde89aa9eebb691826fea279846b531415d224 100644 (file)
@@ -54,7 +54,7 @@ def bind_api(**config):
                                                         api.wait_on_rate_limit_notify)
             self.return_cursors = kwargs.pop('return_cursors', False)
             self.parser = kwargs.pop('parser', api.parser)
-            self.session.headers = kwargs.pop('headers', {})
+            self.headers = kwargs.pop('headers', {})
             self.build_parameters(args, kwargs)
 
             # Pick correct URL root to use
@@ -75,7 +75,7 @@ def bind_api(**config):
             # or older where Host is set including the 443 port.
             # This causes Twitter to issue 301 redirect.
             # See Issue https://github.com/tweepy/tweepy/issues/12
-            self.session.headers['Host'] = self.host
+            self.headers['Host'] = self.host
             # Monitoring rate limits
             self._remaining_calls = None
             self._reset_time = None
@@ -161,12 +161,13 @@ def bind_api(**config):
 
                 # Request compression if configured
                 if self.api.compression:
-                    self.session.headers['Accept-encoding'] = 'gzip'
+                    self.headers['Accept-encoding'] = 'gzip'
 
                 # Execute request
                 try:
                     resp = self.session.request(self.method,
                                                 full_url,
+                                                headers=self.headers,
                                                 data=self.post_data,
                                                 json=self.json_payload,
                                                 timeout=self.api.timeout,