Merge pull request #102 from codl/http-streams
fix #101 by checking if the stream api uses ws:// or wss://
This commit is contained in:
commit
92adc94a77
S'han modificat 1 arxius amb 9 adicions i 2 eliminacions
|
@ -1299,9 +1299,16 @@ class Mastodon:
|
||||||
instance = self.instance()
|
instance = self.instance()
|
||||||
if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url:
|
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
|
# 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"])
|
parse = urlparse(instance["urls"]["streaming_api"])
|
||||||
|
if parse.scheme == 'wss':
|
||||||
url = "https://" + parse.netloc
|
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:
|
else:
|
||||||
url = self.api_base_url
|
url = self.api_base_url
|
||||||
|
|
||||||
|
|
Loading…
Referencia en una nova incidència