@@ -395,18 +395,18 @@ def collect_image(url, user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_
395
395
"""
396
396
try :
397
397
response = requests .get (url , stream = True , timeout = 20 , headers = {"User-Agent" : user_agent })
398
- except requests .exceptions .RequestException as e :
399
- raise FileNotFoundError (f"Unable to download TikTok image via { url } ({ e } ), skipping" )
400
398
401
- if response .status_code != 200 or "image" not in response .headers .get ("content-type" , "" ):
402
- raise FileNotFoundError (f"Unable to download image; status_code:{ response .status_code } content-type:{ response .headers .get ('content-type' , '' )} " )
399
+ if response .status_code != 200 or "image" not in response .headers .get ("content-type" , "" ):
400
+ raise FileNotFoundError (f"Unable to download image; status_code:{ response .status_code } content-type:{ response .headers .get ('content-type' , '' )} " )
403
401
404
- # Process images
405
- image_io = BytesIO (response .content )
406
- try :
407
- picture = Image .open (image_io )
408
- except UnidentifiedImageError :
409
- picture = Image .open (image_io .raw )
402
+ # Process images
403
+ image_io = BytesIO (response .content )
404
+ try :
405
+ picture = Image .open (image_io )
406
+ except UnidentifiedImageError :
407
+ picture = Image .open (image_io .raw )
408
+ except (ConnectionError , requests .exceptions .RequestException ) as e :
409
+ raise FileNotFoundError (f"Unable to download TikTok image via { url } ({ e } ), skipping" )
410
410
411
411
# Grab extension from response
412
412
extension = response .headers ["Content-Type" ].split ("/" )[- 1 ]
0 commit comments