aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcodl <[email protected]>2017-11-22 14:14:35 +0100
committercodl <[email protected]>2017-11-22 14:14:35 +0100
commitc3a31930b8015e6ca62bd38af954e0cf6aa98c3c (patch)
tree00d59550073b32561d21412726640103945a2a48 /mastodon
parent1c137947608f2e5f4591255fa77865f680248423 (diff)
downloadmastodon.py-c3a31930b8015e6ca62bd38af954e0cf6aa98c3c.tar.gz
fix #101 by checking if the stream api uses ws:// or wss://
Diffstat (limited to 'mastodon')
-rw-r--r--mastodon/Mastodon.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 079fc85..3d707ed 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1201,9 +1201,16 @@ class Mastodon:
1201 instance = self.instance() 1201 instance = self.instance()
1202 if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url: 1202 if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url:
1203 # This is probably a websockets URL, which is really for the browser, but requests can't handle it 1203 # This is probably a websockets URL, which is really for the browser, but requests can't handle it
1204 # So we do this below to turn it into an HTTPS URL 1204 # So we do this below to turn it into an HTTPS or HTTP URL
1205 parse = urlparse(instance["urls"]["streaming_api"]) 1205 parse = urlparse(instance["urls"]["streaming_api"])
1206 url = "https://" + parse.netloc 1206 if parse.scheme == 'wss':
1207 url = "https://" + parse.netloc
1208 elif parse.scheme == 'ws':
1209 url = "http://" + parse.netloc
1210 else:
1211 raise MastodonAPIError(
1212 "Could not parse streaming api location returned from server: {}.".format(
1213 instance["urls"]["streaming_api"]))
1207 else: 1214 else:
1208 url = self.api_base_url 1215 url = self.api_base_url
1209 1216
Powered by cgit v1.2.3 (git 2.41.0)