From bf5cfbcf560d8d6494c8f59b15b9710691f192cd Mon Sep 17 00:00:00 2001 From: Lucas Bickel Date: Sun, 15 Oct 2017 14:45:22 +0200 Subject: [PATCH] gracefully handle missing config option --- python_apps/pypo/pypo/pypofile.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python_apps/pypo/pypo/pypofile.py b/python_apps/pypo/pypo/pypofile.py index d63252041..edad6ff92 100644 --- a/python_apps/pypo/pypo/pypofile.py +++ b/python_apps/pypo/pypo/pypofile.py @@ -2,6 +2,7 @@ from threading import Thread from Queue import Empty +from ConfigParser import NoOptionError import logging import shutil @@ -63,14 +64,16 @@ class PypoFile(Thread): CONFIG_SECTION = "general" username = self._config.get(CONFIG_SECTION, 'api_key') baseurl = self._config.get(CONFIG_SECTION, 'base_url') - port = self._config.get(CONFIG_SECTION, 'base_port') - if not port: - port = 80 - protocol = self._config.get(CONFIG_SECTION, 'protocol') - if not protocol: - protocol = str(("http", "https")[int(port) == 443]) try: + port = self._config.get(CONFIG_SECTION, 'base_port') + except NoOptionError, e: + port = 80 + try: + protocol = self._config.get(CONFIG_SECTION, 'protocol') + except NoOptionError, e: + protocol = str(("http", "https")[int(port) == 443]) + try: host = [protocol, baseurl, port] url = "%s://%s:%s/rest/media/%s/download" % (host[0], host[1],