Skip to content

Commit

Permalink
Handle UnidentifiedImageError gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
boramalper committed Jun 21, 2020
1 parent 116a9aa commit 768965a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions nm_iconfinder/nm_iconfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from io import BytesIO

from bs4 import BeautifulSoup
from PIL import Image
from PIL import Image, UnidentifiedImageError
import requests

TIMEOUT = 3 # seconds
Expand Down Expand Up @@ -40,7 +40,10 @@ def from_url(cls, url: str) -> Optional["Icon"]:
return None

with BytesIO(res.content) as bio:
img = Image.open(bio)
try:
img = Image.open(bio)
except UnidentifiedImageError:
return None
width, height = img.size
# Ignore non-square Icons
if width != height:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
setup(
name='nm_iconfinder',
packages=['nm_iconfinder'],
version='0.1',
version='0.1.1',
license='ISC',
description='Find icons of a website given a URL',
author='newsmail.today',
Expand Down

0 comments on commit 768965a

Please sign in to comment.