Fix failing on unavailable page resource

This commit is contained in:
Maks Snegov 2019-11-09 17:33:58 +03:00
parent e6db3f9d1b
commit 6f917578aa

View File

@ -21,8 +21,12 @@ def get_text(url):
def get_embedded_binary(url): def get_embedded_binary(url):
"""Download content from URL and return bytes if target is image""" """Download content from URL and return bytes if target is image"""
response = requests.get(url) try:
response.raise_for_status() response = requests.get(url)
response.raise_for_status()
except requests.exceptions.RequestException:
return ''
ctype = response.headers.get('Content-Type') ctype = response.headers.get('Content-Type')
data = response.content data = response.content
b64pict = base64.b64encode(data).decode() b64pict = base64.b64encode(data).decode()