aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2017-11-22 14:29:24 +0100
committerGitHub <[email protected]>2017-11-22 14:29:24 +0100
commit92adc94a774e1650dba9ba72175d59c4f44a21c5 (patch)
tree8a0d8fa828e73435426600c963536ae6699f1ea2 /mastodon/Mastodon.py
parent8987590545861c3963bdfe7f979e6dc2e9c89fdb (diff)
parentc3a31930b8015e6ca62bd38af954e0cf6aa98c3c (diff)
downloadmastodon.py-92adc94a774e1650dba9ba72175d59c4f44a21c5.tar.gz
Merge pull request #102 from codl/http-streams
fix #101 by checking if the stream api uses ws:// or wss://
Diffstat (limited to 'mastodon/Mastodon.py')
-rw-r--r--mastodon/Mastodon.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index b4d4aa3..d2d634e 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1299,9 +1299,16 @@ class Mastodon:
1299 instance = self.instance() 1299 instance = self.instance()
1300 if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url: 1300 if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url:
1301 # This is probably a websockets URL, which is really for the browser, but requests can't handle it 1301 # This is probably a websockets URL, which is really for the browser, but requests can't handle it
1302 # So we do this below to turn it into an HTTPS URL 1302 # So we do this below to turn it into an HTTPS or HTTP URL
1303 parse = urlparse(instance["urls"]["streaming_api"]) 1303 parse = urlparse(instance["urls"]["streaming_api"])
1304 url = "https://" + parse.netloc 1304 if parse.scheme == 'wss':
1305 url = "https://" + parse.netloc
1306 elif parse.scheme == 'ws':
1307 url = "http://" + parse.netloc
1308 else:
1309 raise MastodonAPIError(
1310 "Could not parse streaming api location returned from server: {}.".format(
1311 instance["urls"]["streaming_api"]))
1305 else: 1312 else:
1306 url = self.api_base_url 1313 url = self.api_base_url
1307 1314
Powered by cgit v1.2.3 (git 2.41.0)