aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-05-06 01:36:48 +0200
committerLorenz Diener <[email protected]>2018-05-06 01:36:48 +0200
commitad6b8eeb044760adf4b420199164b245012350f4 (patch)
tree3f0a23eadfbbf502b0f58c677a333a443e9058d9
parentb9ffcd58c5b0deaf7b94c8d4616cd343067b68c7 (diff)
downloadmastodon.py-ad6b8eeb044760adf4b420199164b245012350f4.tar.gz
Switch to using requests Session objects
-rw-r--r--mastodon/Mastodon.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 1cbb750..fd44d65 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -194,6 +194,8 @@ class Mastodon:
194 194
195 self.request_timeout = request_timeout 195 self.request_timeout = request_timeout
196 196
197 self.session = requests.Session()
198
197 # Versioning 199 # Versioning
198 if mastodon_version == None: 200 if mastodon_version == None:
199 self.retrieve_mastodon_version() 201 self.retrieve_mastodon_version()
@@ -1585,7 +1587,7 @@ class Mastodon:
1585 else: 1587 else:
1586 kwargs['data'] = params 1588 kwargs['data'] = params
1587 1589
1588 response_object = requests.request( 1590 response_object = self.session.request(
1589 method, self.api_base_url + endpoint, **kwargs) 1591 method, self.api_base_url + endpoint, **kwargs)
1590 except Exception as e: 1592 except Exception as e:
1591 raise MastodonNetworkError("Could not complete request: %s" % e) 1593 raise MastodonNetworkError("Could not complete request: %s" % e)
@@ -1739,8 +1741,7 @@ class Mastodon:
1739 # Connect function (called and then potentially passed to async handler) 1741 # Connect function (called and then potentially passed to async handler)
1740 def connect_func(): 1742 def connect_func():
1741 headers = {"Authorization": "Bearer " + self.access_token} 1743 headers = {"Authorization": "Bearer " + self.access_token}
1742 connection = requests.get(url + endpoint, headers = headers, data = params, stream = True) 1744 connection = self.session.get(url + endpoint, headers = headers, data = params, stream = True)
1743
1744 if connection.status_code != 200: 1745 if connection.status_code != 200:
1745 raise MastodonNetworkError("Could not connect to streaming server: %s" % connection.reason) 1746 raise MastodonNetworkError("Could not connect to streaming server: %s" % connection.reason)
1746 return connection 1747 return connection
Powered by cgit v1.2.3 (git 2.41.0)