Commit 63ae5f92 authored by guglielmo's avatar guglielmo

Errors correctly trapped and shown in log messages.

parent 7ae13fe1
......@@ -10,7 +10,7 @@ class Command(LoggingBaseCommand):
help = "Verify content of specified URI's ids or all"
def add_arguments(self, parser):
parser.add_argument('id', nargs='*', type=int)
parser.add_argument('ids', nargs='*', type=int)
parser.add_argument(
'--dry-run',
......@@ -66,15 +66,16 @@ class Command(LoggingBaseCommand):
offset = options['offset']
limit = options['limit']
ids = options.get('ids', [])
if len(args) == 0:
if len(ids) == 0:
if limit > 0:
contents = Content.objects.all()[
offset:(offset + limit)]
else:
contents = Content.objects.all()[offset:]
else:
contents = Content.objects.filter(id__in=args)
contents = Content.objects.filter(id__in=ids)
if len(contents) == 0:
self.logger.info("no content to check this time")
......@@ -98,11 +99,15 @@ class Command(LoggingBaseCommand):
cnt + 1, len(contents), err_msg, content.title, content.id
))
else:
if content.verification_error:
status = content.verification_error
else:
status = content.get_verification_status_display().upper()
self.logger.info(
"{0}/{1} - {2} (id: {4}) - {3}".format(
cnt + 1, len(contents), content.title,
content.get_verification_status_display().upper(),
content.id
status,
content.id,
)
)
if options['showmeat'] is True:
......
......@@ -11,7 +11,9 @@ import lxml.html
from lxml.etree import ParserError
from lxml.html.clean import Cleaner
from lxml.etree import XPathEvalError
from requests.exceptions import SSLError
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@python_2_unicode_compatible
class OrganisationType(models.Model):
......@@ -111,19 +113,26 @@ class Content(models.Model):
when xpath failes status code is 900
"""
try:
headers = {}
if config.REQUESTS_UA:
headers['User-Agent'] = config.REQUESTS_UA
headers = {}
if config.REQUESTS_UA:
headers['User-Agent'] = config.REQUESTS_UA
try:
res = requests.get(self.url, timeout=config.REQUESTS_MAX_TIMEOUT, headers=headers)
if not res.ok:
raise Exception("Internal Urllib error")
if res.status_code != 200:
return res.status_code, "URL"
except ConnectionError:
return 910, "URL inesistente"
if res.status_code and res.reason:
return res.status_code, res.reason
else:
return 990, "Generic error"
except SSLError:
try:
res = requests.get(self.url, timeout=config.REQUESTS_MAX_TIMEOUT, headers=headers, verify=False)
except Exception as e:
return 990, e
except ConnectionError as e:
return 910, e
except Exception as e:
return 990, e
# extract textual content from html,
# using cleaner if set in model
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment