Tweak/fix the attachment caching

This commit is contained in:
Thomas Sileo
2018-07-24 23:58:13 +02:00
parent d544cf893e
commit 619044d285
3 changed files with 10 additions and 3 deletions

View File

@@ -15,6 +15,9 @@ def load(url, user_agent):
"""Initializes a `PIL.Image` from the URL."""
with requests.get(url, stream=True, headers={"User-Agent": user_agent}) as resp:
resp.raise_for_status()
if not resp.headers.get('content-type').startswith('image/'):
raise ValueError(f"bad content-type {resp.headers.get('content-type')}")
resp.raw.decode_content = True
return Image.open(BytesIO(resp.raw.read()))