diff --git a/cps/about.py b/cps/about.py index 7e839520..54f0eb91 100644 --- a/cps/about.py +++ b/cps/about.py @@ -58,10 +58,14 @@ try: except ImportError: greenlet_Version = None +try: + from fake_useragent.errors import FakeUserAgentError +except (ImportError): + FakeUserAgentError = BaseException try: from scholarly import scholarly scholarly_version = _(u'installed') -except ImportError: +except (ImportError, FakeUserAgentError): scholarly_version = _(u'not installed') from . import services diff --git a/cps/editbooks.py b/cps/editbooks.py index f0b8fb41..2f3b1b88 100755 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -33,13 +33,6 @@ try: except ImportError: pass -# Improve this to check if scholarly is available in a global way, like other pythonic libraries -try: - from scholarly import scholarly - have_scholar = True -except ImportError: - have_scholar = False - from flask import Blueprint, request, flash, redirect, url_for, abort, Markup, Response from flask_babel import gettext as _ from flask_login import current_user, login_required diff --git a/cps/metadata_provider/scholar.py b/cps/metadata_provider/scholar.py index df387831..2a8d3cca 100644 --- a/cps/metadata_provider/scholar.py +++ b/cps/metadata_provider/scholar.py @@ -16,7 +16,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from scholarly import scholarly +try: + from fake_useragent.errors import FakeUserAgentError +except (ImportError): + FakeUserAgentError = BaseException +try: + from scholarly import scholarly +except FakeUserAgentError: + raise ImportError("No module named 'scholarly'") from cps.services.Metadata import Metadata