diff --git a/get_solar_flare_png.py b/get_solar_flare_png.py index 560e595..3ec5756 100755 --- a/get_solar_flare_png.py +++ b/get_solar_flare_png.py @@ -7,6 +7,7 @@ from urllib.parse import urljoin import requests +from ska_helpers import retry URL = "https://www.solen.info/solar/index.html" IMAGE_SRC_PATTERN = r" Path: @@ -55,6 +62,8 @@ def get_last_referenced_web_image( # Fetch the web page and get the html response = requests.get(url) + # Check that the request was successful + response.raise_for_status() html = response.text # get absolute url of the image that matches the supplied pattern @@ -80,6 +89,9 @@ def get_last_referenced_web_image( # Download the new image and save it to the cache directory response = requests.get(img_url) + # Check that the request was successful + response.raise_for_status() + with open(cached_image_file, "wb") as f: f.write(response.content) @@ -102,6 +114,8 @@ def main(sys_args=None): if __name__ == "__main__": try: main() + except requests.exceptions.HTTPError as e: + print(f"Failed to get page or image: {e}") except Exception: import traceback