fix network errors

This commit is contained in:
Tomáš Mládek 2020-07-15 03:28:03 +02:00
parent 33a33daa83
commit f19e04c962

View file

@ -6,6 +6,7 @@ from urllib.parse import urlparse
import aiohttp
import psutil
from aiohttp import ClientConnectorError
from bs4 import BeautifulSoup
from django.views.generic import TemplateView
from humanize import naturalsize
@ -30,12 +31,12 @@ class IndexView(TemplateView):
session = aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5, sock_connect=1))
for link in links:
index_text = None, None
index_text = None
if not link.image:
try:
async with session.get(link.url) as response:
index_status, index_text = response.status, await response.text()
except asyncio.TimeoutError:
except (asyncio.TimeoutError, ClientConnectorError):
pass
image = link.image.url if link.image else self.extract_favicon(link.url, index_text)
@ -59,7 +60,7 @@ class IndexView(TemplateView):
try:
async with session.get(service.url) as response:
index_status, index_text = response.status, await response.text()
except asyncio.TimeoutError:
except (asyncio.TimeoutError, ClientConnectorError):
pass
if service.port: