From efc7b53c69117e51b24f406cd6742f65b6a7a62b Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 27 Jun 2015 11:13:40 -0400 Subject: Added another layer of security to catch cases where lxml and html5lib are not installed. --- bs4/diagnose.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'bs4/diagnose.py') diff --git a/bs4/diagnose.py b/bs4/diagnose.py index 4d0b00a..1b71983 100644 --- a/bs4/diagnose.py +++ b/bs4/diagnose.py @@ -33,12 +33,21 @@ def diagnose(data): if 'lxml' in basic_parsers: basic_parsers.append(["lxml", "xml"]) - from lxml import etree - print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION)) + try: + from lxml import etree + print "Found lxml version %s" % ".".join(map(str,etree.LXML_VERSION)) + except ImportError, e: + print ( + "lxml is not installed or couldn't be imported.") + if 'html5lib' in basic_parsers: - import html5lib - print "Found html5lib version %s" % html5lib.__version__ + try: + import html5lib + print "Found html5lib version %s" % html5lib.__version__ + except ImportError, e: + print ( + "html5lib is not installed or couldn't be imported.") if hasattr(data, 'read'): data = data.read() -- cgit v1.2.1