feat: Handle exception durin gposting
This commit is contained in:
parent
1c40d2e769
commit
e02ec77308
@ -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__":
|
||||
|
Loading…
Reference in New Issue
Block a user