diff --git a/external_webpage/data_source_reader.py b/external_webpage/data_source_reader.py index 2a7daed..245215d 100644 --- a/external_webpage/data_source_reader.py +++ b/external_webpage/data_source_reader.py @@ -31,6 +31,9 @@ # Port for configuration PORT_CONFIG = 8008 +# Timeout for url get +URL_GET_TIMEOUT = 60 + class DataSourceReader(object): """ @@ -86,7 +89,7 @@ def _get_json_from_info_page(self, port, group_name): url = 'http://{host}:{port}/group?name={group_name}&format=json'.format( host=self._host, port=port, group_name=group_name) try: - page = requests.get(url) + page = requests.get(url, timeout=URL_GET_TIMEOUT) return page.json() except Exception as e: logger.error("URL not found or json not understood: " + str(url)) @@ -101,7 +104,7 @@ def read_config(self): """ # read config - page = requests.get('http://{}:{}/'.format(self._host, PORT_CONFIG)) + page = requests.get('http://{}:{}/'.format(self._host, PORT_CONFIG), timeout=URL_GET_TIMEOUT) content = page.content.decode("utf-8") corrected_page = content.replace("'", '"')\ .replace("None", "null")\ diff --git a/webserver.py b/webserver.py index abc447a..274a4dd 100644 --- a/webserver.py +++ b/webserver.py @@ -34,11 +34,12 @@ def do_GET(self): This is called by BaseHTTPRequestHandler every time a client does a GET. The response is written to self.wfile """ + instrument = "Not set" try: instrument, callback = get_instrument_and_callback(self.path) - # Warn level so as to avoid many log messages that come from other modules - logger.warning("Connected to from " + str(self.client_address) + " looking at " + str(instrument)) + # Debug is only needed when debugging + logger.debug("Connection from " + str(self.client_address) + " looking at " + str(instrument)) with scraped_data_lock: if instrument == "ALL": @@ -61,11 +62,13 @@ def do_GET(self): self.end_headers() self.wfile.write(response.encode("utf-8")) except ValueError as e: - logger.error(e) + logger.exception("Value Error when getting data from {} for {}: {}".format( + self.client_address, instrument, e)) self.send_response(400) except Exception as e: + logger.exception("Exception when getting data from {} for {}: {}".format( + self.client_address, instrument, e)) self.send_response(404) - logger.error(e) def log_message(self, format, *args): """ By overriding this method and doing nothing we disable writing to console