Skip to content

Commit

Permalink
make attachment more resiliant
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Mar 11, 2024
1 parent 5468785 commit dc174b4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ def extract_message(message):
# process any attachments/files
for attach in message.attachments:
# Download file
resp = requests.get(attach.url, timeout=30)
resp.raise_for_status()
content = bytearray()
try:
resp = requests.get(attach.url, timeout=30)
resp.raise_for_status()
content = resp.content
except requests.exceptions.HTTPError:
print('Unable to download attachment')

attachments.append({
'type': attach.content_type,
'origin_name': attach.filename,
'content': base64.b64encode(resp.content).decode()
'content': base64.b64encode(content).decode()
})

backup_msg = {
Expand Down

0 comments on commit dc174b4

Please sign in to comment.