diff --git a/requirements.txt b/requirements.txt index e2f390a2f81c9ee74c9e6de9b2828170d0ffbd0b..25347902ba1a97774cd7a19d13515b516cf40f7f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,4 @@ -adafruit-blinka==6.10.0 -adafruit-circuitpython-busdevice==5.0.6 adafruit-circuitpython-neopixel-spi==0.9.1 -adafruit-circuitpython-pypixelbuf==2.2.5 -adafruit-platformdetect==3.13.3 -adafruit-pureio==1.1.8 certifi==2020.12.5 chardet==4.0.0 click==7.1.2 diff --git a/stechuhr_client/client.py b/stechuhr_client/client.py index 7aa69b0b77038906716393fc8573ad0eb71849c4..6d0a691077d790b63a86d15d16a98067d045bdaf 100644 --- a/stechuhr_client/client.py +++ b/stechuhr_client/client.py @@ -159,10 +159,9 @@ def build_url(config, endpoint: str = "") -> str: """ Build a URL for requests """ - if config["server"]["port"] == 80: + protocol = "https" + if not config["server"]["https"]: protocol = "http" - else: - protocol = "https" url = '{}://{}/{}'.format(protocol, config["server"]["address"].rstrip("/"), endpoint.lstrip("/")) return url @@ -198,7 +197,7 @@ def send_request(verified_id, config, logger) -> str: Send post request to stechuhr-server Return true if everything was ok, false otherwise """ - if int(config["server"]["port"]) == 443: + if int(config["server"]["https"]): target_address = 'https://{}:{}/'.format(config["server"]["address"], config["server"]["port"]) else: target_address = 'http://{}:{}/'.format(config["server"]["address"], config["server"]["port"]) @@ -370,7 +369,11 @@ def update_id_patterns(config, logger) -> 'Config': logger.debug("Requesting id_pattern update at address: {}".format(url)) # Send request - r = requests.get(url, timeout=config["server"]["timeout"]) + try: + r = requests.get(url, timeout=config["server"]["timeout"]) + except urllib3.exceptions.NewConnectionError as e: + logger.error(f"Couldn't reach server at \"{url}\" (using existing patterns instead): {e}") + return config # If the response was ok update the pattern if it changed, else display a warning if r.ok: diff --git a/stechuhr_client/config.py b/stechuhr_client/config.py index d81cb4815d2d14b0be35a6ad601c8642a2fe2126..b6c77edad9fe55963272b75a29aa3276de0ba5d6 100644 --- a/stechuhr_client/config.py +++ b/stechuhr_client/config.py @@ -24,6 +24,7 @@ dryrun = true [server] address = "127.0.0.1" port = 80 +https = true timeout = 5 verify_cert = true