Skip to content

Commit

Permalink
Catch bad request error in Telegram media download
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-uva committed Oct 24, 2024
1 parent 5d5a0e3 commit 3df74c9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions processors/visualisation/download-telegram-images.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import telethon.errors
from telethon import TelegramClient
from telethon.errors import TimedOutError
from telethon.errors import TimedOutError, BadRequestError

from common.config_manager import config
from backend.lib.processor import BasicProcessor
Expand Down Expand Up @@ -218,7 +218,7 @@ async def get_images(self):
await client.download_media(message, str(path), thumb=-1)
msg_id = message.id
success = True
except (AttributeError, RuntimeError, ValueError, TypeError, TimedOutError) as e:
except (AttributeError, RuntimeError, ValueError, TypeError, TimedOutError, BadRequestError) as e:
filename = f"{entity}-index-{media_done}"
msg_id = str(message.id) if hasattr(message, "id") else f"with index {media_done:,}"
self.dataset.log(f"Could not download image for message {msg_id} ({e})")
Expand Down
4 changes: 2 additions & 2 deletions processors/visualisation/download-telegram-videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pathlib import Path

from telethon import TelegramClient
from telethon.errors import FloodError
from telethon.errors import FloodError, BadRequestError

from common.config_manager import config
from backend.lib.processor import BasicProcessor
Expand Down Expand Up @@ -198,7 +198,7 @@ async def get_videos(self):

msg_id = message.id
success = True
except (AttributeError, RuntimeError, ValueError, TypeError) as e:
except (AttributeError, RuntimeError, ValueError, TypeError, BadRequestError) as e:
filename = f"{entity}-index-{media_done}"
msg_id = str(message.id) if hasattr(message, "id") else f"with index {media_done:,}"
self.dataset.log(f"Could not download video for message {msg_id} ({e})")
Expand Down

0 comments on commit 3df74c9

Please sign in to comment.