From c3a31930b8015e6ca62bd38af954e0cf6aa98c3c Mon Sep 17 00:00:00 2001 From: codl Date: Wed, 22 Nov 2017 14:14:35 +0100 Subject: fix #101 by checking if the stream api uses ws:// or wss:// --- mastodon/Mastodon.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'mastodon') 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: instance = self.instance() if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url: # This is probably a websockets URL, which is really for the browser, but requests can't handle it - # So we do this below to turn it into an HTTPS URL + # So we do this below to turn it into an HTTPS or HTTP URL parse = urlparse(instance["urls"]["streaming_api"]) - url = "https://" + parse.netloc + if parse.scheme == 'wss': + url = "https://" + parse.netloc + elif parse.scheme == 'ws': + url = "http://" + parse.netloc + else: + raise MastodonAPIError( + "Could not parse streaming api location returned from server: {}.".format( + instance["urls"]["streaming_api"])) else: url = self.api_base_url -- cgit v1.2.3