Esempio n. 1
0
        def _get_json_response(apiurl=None):
            assert apiurl is not None

            res = utils_setup.fetch_url(apiurl)

            parsed = json.loads(res.read().decode('utf-8'))

            return parsed
Esempio n. 2
0
        def _get_json_response(wsurl=None, retry=True):
            assert wsurl is not None

            from urllib.parse import urlparse

            up = urlparse(wsurl)
            if not up.scheme:
                # Check for it on the disk...
                if os.path.exists(wsurl):
                    parsed = json.load(open(wsurl, 'rt', encoding='utf-8'))
                else:
                    return None
            else:
                # Go out to the network...
                from urllib.request import URLError
                try:
                    res = utils_setup.fetch_url(wsurl,
                                                debuglevel=self.debug,
                                                interactive=self.interactive)
                except URLError as e:
                    if 'windshare' in up.netloc:
                        # Authentication failure, we need to stop now.
                        if hasattr(e, 'code') and e.code == 401:
                            logger.critical('Unable to authenticate: %s' %
                                            wsurl)
                        else:
                            logger.critical(
                                'Unable to contact Wind Share: %s: %s' %
                                (wsurl, e.reason))

                        logger.critical(
                            "Check your credentials, network and proxy settings."
                        )
                        sys.exit(1)
                    raise e

                try:
                    result = res.read().decode('utf-8')
                except ConnectionResetError:
                    if retry:
                        logger.debug(
                            "%s: Connection reset by peer.  Retrying..." %
                            wsurl)
                        result = _get_json_response(wsurl=wsurl, retry=False)
                        logger.debug("%s: retry successful." % wsurl)
                    else:
                        logger.critical("%s: Connection reset by peer." %
                                        wsurl)
                        logger.critical(
                            "Is there a firewall blocking your connection?")
                        sys.exit(1)

                logger.debug('Result:\n%s' % result)
                parsed = json.loads(result)

            return parsed
Esempio n. 3
0
        def _get_json_response(wsurl=None):
            assert wsurl is not None

            from urllib.parse import urlparse

            up = urlparse(wsurl)
            if not up.scheme:
                # Check for it on the disk...
                if os.path.exists(wsurl):
                    parsed = json.load(open(wsurl, 'rt', encoding='utf-8'))
                else:
                    return None
            else:
                # Go out to the network...
                res = utils_setup.fetch_url(wsurl)
                parsed = json.loads(res.read().decode('utf-8'))

            return parsed
Esempio n. 4
0
        def _get_json_response(apiurl=None, retry=True):
            assert apiurl is not None

            res = utils_setup.fetch_url(apiurl)

            try:
                parsed = json.loads(res.read().decode('utf-8'))
            except ConnectionResetError:
                if retry:
                    logger.debug("%s: Connection reset by peer.  Retrying..." % url)
                    parsed = _get_json_response(apiurl=apiurl, retry=False)
                    logger.debug("%s: retry successful.")
                else:
                    logger.critical("%s: Connection reset by peer." % url)
                    logger.critical("Is there a firewall blocking your connection?")
                    sys.exit(1)

            return parsed