diff --git a/.travis.yml b/.travis.yml index f13d719..fb45bd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,12 +9,12 @@ python: before_install: - pip install -U pip wheel setuptools - + install: - pip install -e .[dev] before_script: -- ci/travis/before_script.sh +- sh ci/travis/before_script.sh script: - python -m coverage run -m unittest discover -v diff --git a/ci/travis/before_script.sh b/ci/travis/before_script.sh old mode 100755 new mode 100644 diff --git a/instalooter/_uadetect.py b/instalooter/_uadetect.py index 4763b43..26b2e1b 100644 --- a/instalooter/_uadetect.py +++ b/instalooter/_uadetect.py @@ -55,7 +55,7 @@ def get_user_agent(port=None, cache=None): # Use webbrowser to connect to the server with the default browser webbrowser.open("http://localhost:{}/".format(port)) # Wait for the request handler to get the request from the browser - user_agent = UserAgentRequestHandler.queue.get() + user_agent = UserAgentRequestHandler.queue.get(True, 5) # Close the server server.shutdown() server.server_close() diff --git a/instalooter/looters.py b/instalooter/looters.py index 70d1a75..1897314 100644 --- a/instalooter/looters.py +++ b/instalooter/looters.py @@ -18,7 +18,7 @@ import fs import six from requests import Session -from six.moves.queue import Queue +from six.moves.queue import Queue, Empty from six.moves.http_cookiejar import FileCookieJar, LWPCookieJar from . import __author__, __name__ as __appname__, __version__ @@ -69,10 +69,14 @@ def _user_agent(cls): """ cache = cls._cachefs() if not cache.isfile(cls._USERAGENT_FILE): - ua = get_user_agent(cache=cache.getsyspath(cls._USERAGENT_FILE)) + try: + ua = get_user_agent(cache=cache.getsyspath(cls._USERAGENT_FILE)) + except Empty: + ua = None if ua is None: - warnings.warn("Could not detect user agent, using default") ua = "Mozilla/5.0 (X11; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0" + warnings.warn("Could not detect user agent, using default: " + ua) + warnings.warn("User agent will be stored in file " + cache.getsyspath(cls._USERAGENT_FILE)) with cache.open("user-agent.txt", "w") as f: f.write(ua) with cache.open(cls._USERAGENT_FILE) as f: