Skip to content

Commit

Permalink
Added Error handling for non JPG/JPEG files
Browse files Browse the repository at this point in the history
  • Loading branch information
6ky committed Jul 19, 2023
1 parent a4651b3 commit e6ff12e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions instagrapi/mixins/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class UploadPhotoMixin:
"""

def photo_rupload(
self, path: Path, upload_id: str = "", to_album: bool = False
) -> tuple:
self, path: Path, upload_id: str = "", to_album: bool = False
) -> tuple:
"""
Upload photo to Instagram
Expand All @@ -139,7 +139,11 @@ def photo_rupload(
tuple
(Upload ID for the media, width, height)
"""
assert isinstance(path, Path), f"Path must been Path, now {path} ({type(path)})"
assert isinstance(path, Path), f"Path must be Path, not {type(path)}"
valid_extensions = ['.jpg', '.jpeg']
if path.suffix.lower() not in valid_extensions:
raise ValueError("Invalid file format. Only JPG/JPEG files are supported.")

# upload_id = 516057248854759
upload_id = upload_id or str(int(time.time() * 1000))
assert path, "Not specified path to photo"
Expand Down Expand Up @@ -225,6 +229,10 @@ def photo_upload(
An object of Media class
"""
path = Path(path)
valid_extensions = ['.jpg', '.jpeg']
if path.suffix.lower() not in valid_extensions:
raise ValueError("Invalid file format. Only JPG/JPEG files are supported.")

upload_id, width, height = self.photo_rupload(path, upload_id)
for attempt in range(10):
self.logger.debug(f"Attempt #{attempt} to configure Photo: {path}")
Expand Down

0 comments on commit e6ff12e

Please sign in to comment.