
import requests
import os


def get_apod():

    os.makedirs("APODs", exist_ok=True)
    try:
        apod_data = requests.get("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY").json()
        image_url = apod_data["url"]
        if image_url.endswith(".gif"):
            return
        image_data = requests.get(image_url, stream=True)
    except requests.HTTPError:
        return

    with open(os.path.join("APODs", os.path.basename(image_url)), "wb") as imagefile:
        for chunk in image_data.iter_content(100000):
            imagefile.write(chunk)
        return os.path.abspath((os.path.join("APODs", os.path.basename(image_url))))



import requests
import os


def get_apod():

    os.makedirs("APODs", exist_ok=True)
    try:
        apod_data = requests.get("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY").json()
        image_url = apod_data["url"]
        if image_url.endswith(".gif"):
            raise TypeError
        image_data = requests.get(image_url, stream=True)
    except (requests.HTTPError or TypeError):
        return

    with open(os.path.join("APODs", os.path.basename(image_url)), "wb") as imagefile:
        for chunk in image_data.iter_content(100000):
            imagefile.write(chunk)
        return os.path.abspath((os.path.join("APODs", os.path.basename(image_url))))


Update 0.6.4 - Fixed exception error
Update 0.6.4
- Fixed exception error
