From e02ec7730880fdcc6ac4cf8a0dd0877b038f9afd Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 22 Oct 2024 00:10:29 +0200 Subject: [PATCH] feat: Handle exception durin gposting --- idescriptor/bot.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/idescriptor/bot.py b/idescriptor/bot.py index 7357d53..b701444 100644 --- a/idescriptor/bot.py +++ b/idescriptor/bot.py @@ -1,3 +1,5 @@ +import logging + import requests from imagebot import settings @@ -86,8 +88,12 @@ def post(): image_path = f"{settings.MEDIA_ROOT}/{image.image}" alt_text = image.alt_text - response = client.post_status_with_image(status_text, image_path, alt_text) - print(response) + try: + response = client.post_status_with_image(status_text, image_path, alt_text) + logging.info(response) + image.set_image_posted() + except requests.exceptions.ConnectionError as e: + logging.error(f"Could not post image: {e}") if __name__ == "__main__":