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


Python exceptions.ProxyError方法代码示例

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


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

示例1: exception_handle

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def exception_handle(method):
    """Handle exception raised by requests library."""

    def wrapper(*args, **kwargs):
        try:
            result = method(*args, **kwargs)
            return result
        except ProxyError:
            LOG.exception('ProxyError when try to get %s.', args)
            raise ProxyError('A proxy error occurred.')
        except ConnectionException:
            LOG.exception('ConnectionError when try to get %s.', args)
            raise ConnectionException('DNS failure, refused connection, etc.')
        except Timeout:
            LOG.exception('Timeout when try to get %s', args)
            raise Timeout('The request timed out.')
        except RequestException:
            LOG.exception('RequestException when try to get %s.', args)
            raise RequestException('Please check out your network.')

    return wrapper 
开发者ID:ziwenxie,项目名称:netease-dl,代码行数:23,代码来源:weapi.py

示例2: test_neutron_exception_is_raised_on_any_request_error

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [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

示例3: get_url

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def get_url(url):
    headers['Referer'] = url
    count = 0
    while True:
        count += 1
        if count < settings['maxtries']:
            proxy = get_proxy()
        else:
            proxy = None
        try:
            resp = request('get', url, headers=headers, proxies={'http': proxy})
            return resp
        except ProxyError:
            if count > settings['maxtries']+2:
                print('Exit: Can not get url.<@get_url>')
                exit(1)
            continue 
开发者ID:A1014280203,项目名称:Ugly-Distributed-Crawler,代码行数:19,代码来源:basic_func.py

示例4: get_url

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def get_url(url):
    headers['Referer'] = url
    count = 0
    while True:
        count += 1
        if count < settings['maxtries']:
            proxy = get_proxy()
        else:
            proxy = None
        try:
            resp = request('get', url, headers=headers, proxies={'http': proxy})
            return resp
        except ProxyError:
            if count > settings['maxtries']+2:
                print('Exit: Could not get url.<@get_url>')
                exit(1)
            continue 
开发者ID:A1014280203,项目名称:Ugly-Distributed-Crawler,代码行数:19,代码来源:basic_func.py

示例5: test_no_proxy_domain_fail

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_no_proxy_domain_fail(self, socks5_proxy):
        instance = {'proxy': {'http': 'http://1.2.3.4:567', 'no_proxy': '.google.com,example.com,example,9'}}
        init_config = {}
        http = RequestsWrapper(instance, init_config)

        # no_proxy not match: .google.com
        # ".y.com" matches "x.y.com" but not "y.com"
        with pytest.raises((ConnectTimeout, ProxyError)):
            http.get('http://google.com', timeout=1)

        # no_proxy not match: example or example.com
        with pytest.raises((ConnectTimeout, ProxyError)):
            http.get('http://notexample.com', timeout=1)

        with pytest.raises((ConnectTimeout, ProxyError)):
            http.get('http://example.org', timeout=1)

        # no_proxy not match: 9
        with pytest.raises((ConnectTimeout, ProxyError)):
            http.get('http://127.0.0.99', timeout=1) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:22,代码来源:test_http.py

示例6: delete

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def delete(self):
        """Delete the Case Management Object.

        If no id is present in the obj then returns immediately.
        """
        if not self.id:  # pragma: no cover
            self.tcex.log.warning('A case without an ID cannot be deleted.')
            return

        url = f'{self.api_endpoint}/{self.id}'
        r = None
        try:
            r = self.tcex.session.delete(url)
            self.tcex.log.debug(
                f'Method: ({r.request.method.upper()}), '
                f'Status Code: {r.status_code}, '
                f'URl: ({r.url})'
            )
        except (ConnectionError, ProxyError):  # pragma: no cover
            self.tcex.handle_error(
                951, ['OPTIONS', 407, '{\"message\": \"Connection Error\"}', self.api_endpoint]
            )
        if len(r.content) < 5000:
            self.tcex.log.debug(u'response text: {}'.format(r.text))
        else:  # pragma: no cover
            self.tcex.log.debug(u'response text: (text to large to log)')
        if not self.success(r):
            err = r.text or r.reason
            if r.status_code == 404:
                self.tcex.handle_error(952, [r.request.method.upper(), r.status_code, err, r.url])
            self.tcex.handle_error(950, [r.status_code, err, r.url])
        return 
开发者ID:ThreatConnect-Inc,项目名称:tcex,代码行数:34,代码来源:common_case_management.py

示例7: properties

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def properties(self):
        """Return defined API properties for the current object."""
        if self._properties is None:
            try:
                r = self.tcex.session.options(self.api_endpoint, params={'show': 'readOnly'})
                if r.ok:
                    self._properties = r.json()
            except (ConnectionError, ProxyError):
                self.tcex.handle_error(
                    951, ['OPTIONS', 407, '{\"message\": \"Connection Error\"}', self.api_endpoint]
                )
        return self._properties 
开发者ID:ThreatConnect-Inc,项目名称:tcex,代码行数:14,代码来源:common_case_management.py

示例8: test_unreachable_proxy

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_unreachable_proxy(self, proxy_host):
        session = requests.Session()
        with pytest.raises(ProxyError):
            session.get(arbitrary_url, proxies=proxy_parameter_for_requests('http://' + proxy_host)) 
开发者ID:carsonyl,项目名称:pypac,代码行数:6,代码来源:test_api.py

示例9: test_timeout_proxy

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_timeout_proxy(self):
        # Travis can refuse quickly, and trigger ProxyError instead.
        session = requests.Session()
        with pytest.raises(ConnectTimeout):
            session.get(arbitrary_url, timeout=0.001, proxies=proxy_parameter_for_requests('http://localhost')) 
开发者ID:carsonyl,项目名称:pypac,代码行数:7,代码来源:test_api.py

示例10: test_bad_proxy_no_failover

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_bad_proxy_no_failover(self, proxy_host):
        """Verify that Requests returns ProxyError when given a non-existent proxy."""
        sess = PACSession(pac=PACFile(proxy_pac_js_tpl % 'PROXY %s:80' % proxy_host))
        with pytest.raises(ProxyError):
            sess.get(arbitrary_url) 
开发者ID:carsonyl,项目名称:pypac,代码行数:7,代码来源:test_api.py

示例11: test_pac_failover

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_pac_failover(self):
        """First proxy raises error. Transparently fail over to second proxy."""
        sess = PACSession(pac=PACFile(proxy_pac_js_tpl % 'PROXY a:80; PROXY b:80; DIRECT'))

        def fake_request(method, url, proxies=None, **kwargs):
            if proxies and proxies['http'] == 'http://a:80':
                raise ProxyError()

        with _patch_request_base(side_effect=fake_request) as request:
            sess.get(arbitrary_url)
            request.assert_has_calls([
                get_call(arbitrary_url, 'http://a:80'),
                get_call(arbitrary_url, 'http://b:80'),
            ]) 
开发者ID:carsonyl,项目名称:pypac,代码行数:16,代码来源:test_api.py

示例12: test_pac_failover_to_direct

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_pac_failover_to_direct(self):
        """Proxy fails. Next in line is DIRECT keyword."""
        sess = PACSession(pac=PACFile(proxy_pac_js))

        def fake_request_reject_proxy(method, url, proxies=None, **kwargs):
            if proxies and proxies['http'] is not None:
                raise ProxyError()

        with _patch_request_base(side_effect=fake_request_reject_proxy) as request:
            sess.get(arbitrary_url)
            request.assert_has_calls([
                get_call(arbitrary_url, fake_proxy_url),
                get_call(arbitrary_url, 'DIRECT'),
            ]) 
开发者ID:carsonyl,项目名称:pypac,代码行数:16,代码来源:test_api.py

示例13: test_pac_no_failover_available_exc_case

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def test_pac_no_failover_available_exc_case(self):
        """Special case where proxy fails but there's no DIRECT fallback. Error should bubble up,
        and all applicable proxies should be tried again in the next request. Proxy failure from exception."""
        sess = PACSession(pac=PACFile(proxy_pac_js_tpl % 'PROXY a:80; PROXY b:80'))
        for _ in range(2):
            with _patch_request_base(side_effect=ProxyError()) as request, \
                    pytest.raises(ProxyError):
                sess.get(arbitrary_url)
            request.assert_has_calls([
                get_call(arbitrary_url, 'http://a:80'),
                get_call(arbitrary_url, 'http://b:80'),
            ]) 
开发者ID:carsonyl,项目名称:pypac,代码行数:14,代码来源:test_api.py

示例14: default_proxy_fail_exception_filter

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def default_proxy_fail_exception_filter(req_exc):
    return isinstance(req_exc, (ProxyError, ConnectTimeout)) 
开发者ID:carsonyl,项目名称:pypac,代码行数:4,代码来源:api.py

示例15: main

# 需要导入模块: from requests import exceptions [as 别名]
# 或者: from requests.exceptions import ProxyError [as 别名]
def main():
    count = 0
    while True:
        # print('第 ',count,' 次测试')
        count = count + 1
        try:
            #请求不同的代理和headers
            global headers,count_proxys
            headers = {'User-Agent': ua.random}
            count_proxys = get_count_proxys()
            print('代理总数: ',count_proxys,'  当前所用的代理:',proxy,'\n',headers)
            start_time = time.clock()
            html = crawl('http://www.baidu.com', proxy)
            end_time = time.clock()
            print('代理连接时间: ',(str(end_time-start_time))[:4],' 秒')
            if html.status_code==200:
                print(html)
                return count
                break
            elif count>=10:
                print('抓取网页失败')
                break

        except (ChunkedEncodingError,ConnectionError,Timeout,UnboundLocalError,UnicodeError,ProxyError):
            global proxy
            proxy = get_proxy()
            print('代理失败,更换代理','\n')
            # print(' ') 
开发者ID:Germey,项目名称:ProxyPool,代码行数:30,代码来源:example_round_proxy.py


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