当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.TooManyRedirects方法代码示例

本文整理汇总了Python中requests.exceptions.TooManyRedirects方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TooManyRedirects方法的具体用法?Python exceptions.TooManyRedirects怎么用?Python exceptions.TooManyRedirects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests.exceptions的用法示例。


在下文中一共展示了exceptions.TooManyRedirects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_neutron_exception_is_raised_on_any_request_error

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def test_neutron_exception_is_raised_on_any_request_error(self):
        # timeout exception raises InfobloxTimeoutError
        f = mock.Mock()
        f.__name__ = 'mock'
        f.side_effect = req_exc.Timeout
        self.assertRaises(exceptions.InfobloxTimeoutError,
                          connector.reraise_neutron_exception(f))

        # all other request exception raises InfobloxConnectionError
        supported_exceptions = [req_exc.HTTPError,
                                req_exc.ConnectionError,
                                req_exc.ProxyError,
                                req_exc.SSLError,
                                req_exc.TooManyRedirects,
                                req_exc.InvalidURL]

        for ex in supported_exceptions:
            f.side_effect = ex
            self.assertRaises(exceptions.InfobloxConnectionError,
                              connector.reraise_neutron_exception(f)) 
开发者ID:infobloxopen,项目名称:infoblox-client,代码行数:22,代码来源:test_connector.py

示例2: get_listings

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def get_listings(start=1,limit=1000):
    parameters = {
        'start': start,
        'limit': str(limit),
        'convert': 'USD',
        'sort': 'market_cap'
    }
    #sort=market_cap&start=1&limit=10&cryptocurrency_type=tokens&convert=USD,BTC
    headers = {
        'Accepts': 'application/json',
        'X-CMC_PRO_API_KEY': cmc_key,
    }

    session = Session()
    session.headers.update(headers)

    endpoint_summary = 'cryptocurrency/listings/latest'
    try:
        url = base_url + endpoint_summary
        response = session.get(url, params=parameters)
        data = json.loads(response.text)["data"]
        return data
    except (ConnectionError, Timeout, TooManyRedirects) as e:
        print(e) 
开发者ID:economicnetwork,项目名称:archon,代码行数:26,代码来源:coinmarketcap.py

示例3: get_info

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def get_info(idlist):
    endpoint_description = "cryptocurrency/info"
    
    #[str(x)+',' for x in range(1,20)]
    parameters = {
        #'symbol': 'BTC,ETH,XRP,LTC'
        'id':idlist
    }
    headers = {
        'Accepts': 'application/json',
        'X-CMC_PRO_API_KEY': cmc_key,
    }

    session = Session()
    session.headers.update(headers)

    try:
        url = base_url + endpoint_description
        response = session.get(url, params=parameters)
        data = json.loads(response.text)["data"]
        return data
    except (ConnectionError, Timeout, TooManyRedirects) as e:
        print("error ", e) 
开发者ID:economicnetwork,项目名称:archon,代码行数:25,代码来源:coinmarketcap.py

示例4: get_coin_map

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def get_coin_map(active):
    endpoint_map = "cryptocurrency/map"    
    parameters = {
        'listing_status': active
    }
    headers = {
        'Accepts': 'application/json',
        'X-CMC_PRO_API_KEY': cmc_key,
    }

    session = Session()
    session.headers.update(headers)

    try:
        url = base_url + endpoint_map
        response = session.get(url, params=parameters)
        data = json.loads(response.text)["data"]
        return data
    except (ConnectionError, Timeout, TooManyRedirects) as e:
        print(e) 
开发者ID:economicnetwork,项目名称:archon,代码行数:22,代码来源:coinmarketcap.py

示例5: exchange_map

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def exchange_map():    
    endpoint_map = "exchange/map"
    parameters = {
        #'listing_status': active
    }
    #limit
    #slug
    headers = {
        'Accepts': 'application/json',
        'X-CMC_PRO_API_KEY': cmc_key,
    }

    session = Session()
    session.headers.update(headers)

    try:
        url = base_url + endpoint_map
        response = session.get(url, params=parameters)
        data = json.loads(response.text)
        return data
    except (ConnectionError, Timeout, TooManyRedirects) as e:
        print(e) 
开发者ID:economicnetwork,项目名称:archon,代码行数:24,代码来源:coinmarketcap.py

示例6: _detect_by_application

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def _detect_by_application(self):
        try:
            session = self.request_handler.get_new_session()
            response = session.get(
                timeout=20,
                allow_redirects=True,
                url="{}://{}:{}".format(
                    self.host.protocol,
                    self.host.target,
                    self.host.port
                )
            )
            for waf, method in self.waf_app_method_map.items():
                result = method(response)
                if result:
                    self._waf_detected(waf, "web application")

        except (ConnectionError, TooManyRedirects) as e:
            raise WAFException("Couldn't get response from server.\n"
                               "Caused due to exception: {}".format(str(e))) 
开发者ID:evyatarmeged,项目名称:Raccoon,代码行数:22,代码来源:waf.py

示例7: test_get_should_invalid_cache_on_too_many_redirects_error

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def test_get_should_invalid_cache_on_too_many_redirects_error(mocker):
    delete_cache = mocker.patch("cachecontrol.caches.file_cache.FileCache.delete")

    response = Response()
    response.encoding = "utf-8"
    response.raw = BytesIO(encode('{"foo": "bar"}'))
    mocker.patch(
        "cachecontrol.adapter.CacheControlAdapter.send",
        side_effect=[TooManyRedirects(), response],
    )
    repository = PyPiRepository()
    repository._get("https://pypi.org/pypi/async-timeout/json")

    assert delete_cache.called 
开发者ID:python-poetry,项目名称:poetry,代码行数:16,代码来源:test_pypi_repository.py

示例8: _get

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def _get(self, endpoint):  # type: (str) -> Union[dict, None]
        try:
            json_response = self._session.get(self._base_url + endpoint)
        except TooManyRedirects:
            # Cache control redirect loop.
            # We try to remove the cache and try again
            self._cache_control_cache.delete(self._base_url + endpoint)
            json_response = self._session.get(self._base_url + endpoint)

        if json_response.status_code == 404:
            return None

        json_data = json_response.json()

        return json_data 
开发者ID:python-poetry,项目名称:poetry,代码行数:17,代码来源:pypi_repository.py

示例9: http

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def http(self, method, host, payload=''):
    print 'HTTP %s %s: %s' % (method, host, payload)
    methodfn = getattr(requests, method.lower(), None)
    if method is None:
      raise NotImplementedError("requests module has not method %s " % method)
    try:
      if payload != '':
        request = methodfn(url='%s/%s' % (self.hosturl, host), data=json.dumps(payload), auth=self.auth, verify=False)
      else:
        request = methodfn(url='%s/%s' % (self.hosturl, host), auth=self.auth, verify=False)

      if request.status_code != requests.codes.ok:
        request.raise_for_status()

      rc = 0
      out = json.loads(request.text)
      err = ''
    except (ConnectionError, HTTPError, Timeout, TooManyRedirects) as e:
      rc = 1
      out = ''
      err = '%s. Error received: %s.\n Sent request: %s' % (
          e.message, json.loads(request.text), 'HTTP %s %s: %s' % (method, host, payload))

    print 'HTTP %s returned: %s' % (method, request.text)

    return (rc, out, err) 
开发者ID:f5devcentral,项目名称:aws-deployments,代码行数:28,代码来源:manual_bigip_config.py

示例10: http

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def http(self, method, uri, payload=''):
    payload_str = json.dumps(payload)
    methodfn = getattr(requests, method.lower(), None)
    
    if method is None:
      raise NotImplementedError("requests module has not method %s " % method)
    try:
      if payload:
        request = methodfn(url='%s/%s' % (self.hosturl, uri), data=payload_str, auth=self.auth, verify=False)
      else:
        request = methodfn(url='%s/%s' % (self.hosturl, uri), auth=self.auth, verify=False)

      if request.status_code != requests.codes.ok:
        request.raise_for_status()

      rc = 0
      out = json.loads(request.text)
      err = ''
    except (ConnectionError, HTTPError, Timeout, TooManyRedirects) as e:
      rc = 1
      out = ""
      err = "Error sent request: HTTP %s %s: %s\n. Received error: %s" % (method, uri, payload_str,
        getattr(request, "text", ""))


    return (rc, out, err) 
开发者ID:f5devcentral,项目名称:aws-deployments,代码行数:28,代码来源:bigip_config.py

示例11: fetch

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def fetch(self, path, params=None):
        try:
            response = self.session.get(
                    '{}{}'.format(self.PRODUCTION_BASE_URL, path),
                    params=params)
            data = json.loads(response.text)
            return data
        except (ConnectionError, Timeout, TooManyRedirects) as e:
            self.logger.log(e) 
开发者ID:msantl,项目名称:cryptofolio,代码行数:11,代码来源:Coinmarket.py

示例12: send

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def send(self, method="GET", *args, **kwargs):
        """
        Send a GET/POST/HEAD request using the object's proxies and headers
        :param method: Method to send request in. GET/POST/HEAD
        """
        proxies = self._get_request_proxies()

        try:
            if method.upper() in self.allowed_methods:
                kwargs['timeout'] = kwargs['timeout'] if 'timeout' in kwargs else 5
                return request(method, proxies=proxies, headers=self.headers, cookies=self.cookies, *args, **kwargs)
            else:
                raise RequestHandlerException("Unsupported method: {}".format(method))
        except ProxyError:
            # TODO: Apply fail over for bad proxies or drop them
            raise RequestHandlerException("Error connecting to proxy")
        except (ConnectTimeout, ReadTimeout):
            raise RequestHandlerException("Connection with server timed out")
        except NewConnectionError:
            raise RequestHandlerException("Address cannot be resolved")
            # New connection error == Can't resolve address
        except ConnectionError:
            # TODO: Increase delay
            raise RequestHandlerException("Error connecting to host")
        except TooManyRedirects:
            raise RequestHandlerException("Infinite redirects detected - too many redirects error")
        except UnicodeDecodeError:
            # Following issue #19, apparently some sites do not use utf-8 in their uris :<>
            pass 
开发者ID:evyatarmeged,项目名称:Raccoon,代码行数:31,代码来源:request_handler.py

示例13: get_web_application_info

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def get_web_application_info(self):
        session = self.request_handler.get_new_session()
        try:
            with session:
                # Test if target is serving HTTP requests
                response = session.get(
                    timeout=20,
                    url="{}://{}:{}".format(
                        self.host.protocol,
                        self.host.target,
                        self.host.port
                    )
                )
                self.headers = response.headers
                self._detect_cms()
                self._robots()
                self._sitemap()
                self._server_info()
                self._x_powered_by()
                self._cors_wildcard()
                self._xss_protection()
                self._anti_clickjacking()
                self._cookie_info(session.cookies)

                soup = BeautifulSoup(response.text, "lxml")
                self._find_urls(soup)
                self._find_forms(soup)
                self.storage_explorer.run(soup)

        except (ConnectionError, TooManyRedirects) as e:
            raise WebAppScannerException("Couldn't get response from server.\n"
                                         "Caused due to exception: {}".format(str(e))) 
开发者ID:evyatarmeged,项目名称:Raccoon,代码行数:34,代码来源:web_app.py

示例14: __call__

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def __call__(self, **kwargs):
        self._settings = kwargs
        self._proxy = {
            'http': kwargs['proxy'],
            'https': kwargs['proxy'],
        } if 'proxy' in kwargs else None
        requests_per_minute = kwargs['requests_per_minute']
        self._min_request_interval = 60 / requests_per_minute
        self._local_object_duration = kwargs['local_object_duration']
        self._broadcast_incremental_backup = kwargs['broadcast_incremental_backup']
        self._image_local_cache = kwargs['image_local_cache']
        self._broadcast_active_duration = kwargs['broadcast_active_duration']
        self._last_request_at = time()
        session = requests.Session()
        session.headers.update({
            'Cookie': self._account.session,
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.105 Safari/537.36',
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding': 'gzip, deflate, br',
            'Accept-Language': 'zh-CN,zh;q=0.8',
            'Referer': 'https://www.douban.com/',
            'Pragma': 'no-cache',
            'Cache-Control': 'no-cache',
        })
        self._request_session = session

        cookie = cookies.SimpleCookie()
        cookie.load(self._account.session)
        self._account_cookie = cookie

        try:
            return self.run()
        except (TooManyRedirects, Forbidden):
            logging.debug('Login session maybe forbidden')
            self._account.is_invalid = True
            self._account.save()
            return False
        #except Exception as e:
        #    logging.debug(e)
        #    return False
        finally:
            session.close() 
开发者ID:tabris17,项目名称:doufen,代码行数:44,代码来源:tasks.py

示例15: request3

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import TooManyRedirects [as 别名]
def request3(self, url, method="post", stream=False, data=None):
        self.last_url = url
        self.last_data = None
        self.r = None
        self.response = None
        self.last_error_message = "Not yet set by request3 function"
        if data is None:
            data = dict()
        data_json = json.dumps(data)
        headers = {
            "X-API-TOKEN": self.token,
            "Content-Type": "application/json"
        }
        try:
            if method == "post":
                self.last_data = data
                r = requests.post(url, data=data_json, headers=headers)
            elif method == "get":
                r = requests.get(url, headers=headers)
            else:
                raise NotImplementedError("method %s is not supported" % method)
        except (ConnectionError, Timeout, TooManyRedirects, HTTPError) as e:
            # http://docs.python-requests.org/en/master/user/quickstart/#errors-and-exceptions
            # ConnectionError: In the event of a network problem (e.g. DNS failure, refused connection, etc) Requests will raise a ConnectionError exception.
            # HTTPError: Response.raise_for_status() will raise an HTTPError if the HTTP request returned an unsuccessful status code.
            # Timeout: If a request times out, a Timeout exception is raised.
            # TooManyRedirects: If a request exceeds the configured number of maximum redirections, a TooManyRedirects exception is raised.
            self.last_error_message = str(e)
            return None
        self.r = r
        self.response = r.text   # Keep this for backward compatibility with previous versions
        try:
            self.json_response = r.json()
        except:
            self.json_response = None
        if r.status_code != 200:
            # HTTP server error: 404, 500 etc
            # Apparently http code 401 Unauthorized is returned when incorrect token is provided
            self.last_error_message = "HTTP Code %s" % r.status_code
            try:
                if "error" in self.json_response["meta"]:
                    self.last_error_message = self.json_response["meta"]["error"]["errorMessage"]
                    return None
            except:
                # Mailformed response from the server
                pass
            return None

        return r 
开发者ID:Baguage,项目名称:pyqualtrics,代码行数:51,代码来源:__init__.py


注:本文中的requests.exceptions.TooManyRedirects方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。