feat: Handle exception durin gposting
This commit is contained in:
parent
1c40d2e769
commit
e02ec77308
@ -1,3 +1,5 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from imagebot import settings
|
from imagebot import settings
|
||||||
@ -86,8 +88,12 @@ def post():
|
|||||||
image_path = f"{settings.MEDIA_ROOT}/{image.image}"
|
image_path = f"{settings.MEDIA_ROOT}/{image.image}"
|
||||||
alt_text = image.alt_text
|
alt_text = image.alt_text
|
||||||
|
|
||||||
|
try:
|
||||||
response = client.post_status_with_image(status_text, image_path, alt_text)
|
response = client.post_status_with_image(status_text, image_path, alt_text)
|
||||||
print(response)
|
logging.info(response)
|
||||||
|
image.set_image_posted()
|
||||||
|
except requests.exceptions.ConnectionError as e:
|
||||||
|
logging.error(f"Could not post image: {e}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user