Use proper protocol in URL if port is set to 443

This adds TLS support to pypo when downloading files from the REST
API. I previously fixed some similar issues in the api_client and
wasn't aware that pypo isn't using it for every URL..
This commit is contained in:
Lucas Bickel 2017-07-21 12:27:34 +02:00
parent 6e2cb2b2a8
commit 0a556adbfa

View file

@ -64,8 +64,12 @@ class PypoFile(Thread):
username = self._config.get(CONFIG_SECTION, 'api_key')
host = self._config.get(CONFIG_SECTION, 'base_url')
port = self._config.get(CONFIG_SECTION, 'base_port', 80)
url = "http://%s:%s/rest/media/%s/download" % (host, port, media_item["id"])
self.logger.error(url)
url = "%s://%s:%s/rest/media/%s/download" % (str(("http", "https")[int(port) == 443]),
host,
port,
media_item["id"])
self.logger.info(url)
with open(dst, "wb") as handle:
response = requests.get(url, auth=requests.auth.HTTPBasicAuth(username, ''), stream=True, verify=False)