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


Python exceptions.InsecureRequestWarning方法代码示例

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


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

示例1: __init__

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def __init__(self):
        self._session = requests.Session()
        self._captcha_handler = None
        self._timeout = 5  # 每个请求的超时(不包含下载响应体的用时)
        self._max_size = 100  # 单个文件大小上限 MB
        self._upload_delay = (0, 0)  # 文件上传延时
        self._host_url = 'https://www.lanzous.com'
        self._doupload_url = 'https://pc.woozooo.com/doupload.php'
        self._account_url = 'https://pc.woozooo.com/account.php'
        self._mydisk_url = 'https://pc.woozooo.com/mydisk.php'
        self._cookies = None
        self._headers = {
            'User-Agent': USER_AGENT,
            'Referer': 'https://www.lanzous.com',
            'Accept-Language': 'zh-CN,zh;q=0.9',  # 提取直连必需设置这个,否则拿不到数据
        }
        disable_warnings(InsecureRequestWarning)  # 全局禁用 SSL 警告 
开发者ID:rachpt,项目名称:lanzou-gui,代码行数:19,代码来源:core.py

示例2: __init__

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def __init__(self):
        self._session = requests.Session()
        self._captcha_handler = None
        self._limit_mode = True  # 是否保持官方限制
        self._timeout = 15  # 每个请求的超时(不包含下载响应体的用时)
        self._max_size = 100  # 单个文件大小上限 MB
        self._upload_delay = (0, 0)  # 文件上传延时
        self._host_url = 'https://www.lanzous.com'
        self._doupload_url = 'https://pc.woozooo.com/doupload.php'
        self._account_url = 'https://pc.woozooo.com/account.php'
        self._mydisk_url = 'https://pc.woozooo.com/mydisk.php'
        self._cookies = None
        self._headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
            'Referer': 'https://www.lanzous.com',
            'Accept-Language': 'zh-CN,zh;q=0.9',  # 提取直连必需设置这个,否则拿不到数据
        }
        disable_warnings(InsecureRequestWarning)  # 全局禁用 SSL 警告 
开发者ID:zaxtyson,项目名称:LanZouCloud-API,代码行数:20,代码来源:core.py

示例3: enter_contexts

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def enter_contexts(self):
        self._requests = yield requests.Session()

        proxies = self.settings.get('PROXIES')
        if proxies:
            self._requests.proxies = proxies

        verify_ssl = self.settings.get('VERIFY_SSL', True)
        self._requests.verify = verify_ssl
        if not verify_ssl:
            urllib3.disable_warnings(InsecureRequestWarning)

        self._requests.headers.update(DEFAULT_HEADERS)
        user_agent = self.settings.get('USER_AGENT')
        if user_agent is not None:
            self._requests.headers['User-Agent'] = user_agent
        else:
            self._requests.headers.pop('User-Agent', None)

        response = self._requests.get(URLS['start'])
        response.raise_for_status()
        self._update_csrftoken(response)
        self._update_rhx_gis(response)

        self.rate_limiter = RateLimiter(self) 
开发者ID:pauloromeira,项目名称:onegram,代码行数:27,代码来源:session.py

示例4: __init__

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def __init__(self, phone, country_data, sms_text='Произошёл троллинг'):
        self.phone = phone
        self.country_code = country_data[0]
        self.phone_code = country_data[1]
        self.sms_text = sms_text if sms_text != '' else 'Произошёл троллинг'
        self.formatted_phone = self.phone_code + self.phone
        self.session = requests.Session()

        if os.path.isfile('debug'):
            self.session_get = self.session.get
            self.session_post = self.session.post
            self.session.get = self.get
            self.session.post = self.post

        self.session.headers = {'User-Agent': self.generate_random_user_agent()}
        requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) 
开发者ID:Denishnc,项目名称:b0mb3r,代码行数:18,代码来源:service.py

示例5: test_ssl_verify_not_raise_warning

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def test_ssl_verify_not_raise_warning(mocked_openmetrics_check_factory, text_data):
    instance = dict(
        {
            'prometheus_url': 'https://www.example.com',
            'metrics': [{'foo': 'bar'}],
            'namespace': 'openmetrics',
            'ssl_verify': False,
        }
    )
    check = mocked_openmetrics_check_factory(instance)
    scraper_config = check.get_scraper_config(instance)

    with pytest.warns(None) as record:
        resp = check.send_request('https://httpbin.org/get', scraper_config)

    assert "httpbin.org" in resp.content.decode('utf-8')
    assert all(not issubclass(warning.category, InsecureRequestWarning) for warning in record) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:19,代码来源:test_openmetrics.py

示例6: test_send_request_with_dynamic_prometheus_url

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def test_send_request_with_dynamic_prometheus_url(mocked_openmetrics_check_factory, text_data):
    instance = dict(
        {
            'prometheus_url': 'https://www.example.com',
            'metrics': [{'foo': 'bar'}],
            'namespace': 'openmetrics',
            'ssl_verify': False,
        }
    )
    check = mocked_openmetrics_check_factory(instance)
    scraper_config = check.get_scraper_config(instance)

    # `prometheus_url` changed just before calling `send_request`
    scraper_config['prometheus_url'] = 'https://www.example.com/foo/bar'

    with pytest.warns(None) as record:
        resp = check.send_request('https://httpbin.org/get', scraper_config)

    assert "httpbin.org" in resp.content.decode('utf-8')
    assert all(not issubclass(warning.category, InsecureRequestWarning) for warning in record) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:22,代码来源:test_openmetrics.py

示例7: openshift_container

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def openshift_container(request, port, pytestconfig):
    capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')
    client = docker.from_env()
    openshift_version = request.config.getoption('--openshift-version')
    if openshift_version is None:
        yield None
    else:
        container = client.containers.run(
            'openshift/origin:{}'.format(openshift_version),
            'start master --listen=0.0.0.0:{}'.format(port),
            detach=True,
            ports={port: port}
        )

        try:
            # Wait for the container to no longer be in the created state before
            # continuing
            while container.status == u'created':
                capmanager.suspend()
                print("\nWaiting for container...")
                capmanager.resume()
                time.sleep(5)
                container = client.containers.get(container.id)

            # Disable InsecureRequest warnings because we can't get the cert yet
            warnings.simplefilter('ignore', InsecureRequestWarning)
            # Wait for the api server to be ready before continuing
            for _ in range(10):
                try:
                    requests.head("https://127.0.0.1:{}/healthz/ready".format(port), verify=False)
                except requests.RequestException:
                    pass
                time.sleep(1)
            warnings.simplefilter('default', InsecureRequestWarning)

            time.sleep(1)

            yield container
        finally:
            # Always remove the container
            container.remove(force=True) 
开发者ID:openshift,项目名称:openshift-restclient-python,代码行数:43,代码来源:conftest.py

示例8: _send_request

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def _send_request(self, server, domain, username, password, port,
                      ntlm_compatibility, legacy=True):
        """
        Sends a request to the url with the credentials specified. Returns the
        final response
        """
        # filter out warnings around older Python and unverified connections
        try:
            from requests.packages.urllib3.exceptions import \
                InsecurePlatformWarning
            warnings.simplefilter('ignore', category=InsecurePlatformWarning)
        except ImportError:
            pass

        try:
            from requests.packages.urllib3.exceptions import SNIMissingWarning
            warnings.simplefilter('ignore', category=SNIMissingWarning)
        except ImportError:
            pass

        try:
            from urllib3.exceptions import InsecureRequestWarning
            warnings.simplefilter('ignore', category=InsecureRequestWarning)
        except ImportError:
            pass

        url = "%s://%s:%d/contents.txt" \
              % ('http' if str(port).startswith('8') else 'https',
                 server, port)
        session = requests.Session()
        session.verify = False
        session.auth = NtlmAuth(domain, username, password, ntlm_compatibility,
                                legacy)
        request = requests.Request('GET', url)
        prepared_request = session.prepare_request(request)
        response = session.send(prepared_request)

        return response


# used by the functional tests to auth with an NTLM endpoint 
开发者ID:jborean93,项目名称:ntlm-auth,代码行数:43,代码来源:test_ntlm.py

示例9: connection_handler

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def connection_handler(session, request, verify, as_is_reply=False):
    air = as_is_reply
    s = session
    r = request
    v = verify
    return_json = False

    disable_warnings(InsecureRequestWarning)

    try:
        get = s.send(r, verify=v)
        if get.status_code == 401:
            if 'NoSiteContext' in str(get.content):
                logger.info('Your Site is incorrect for %s', r.url)
            elif 'LoginRequired' in str(get.content):
                logger.info('Your login credentials are incorrect for %s', r.url)
            else:
                logger.info('Your api key is incorrect for %s', r.url)
        elif get.status_code == 404:
            logger.info('This url doesnt even resolve: %s', r.url)
        elif get.status_code == 200:
            try:
                return_json = get.json()
            except JSONDecodeError:
                logger.error('No JSON response. Response is: %s', get.text)
        if air:
            return get
    except InvalidSchema:
        logger.error("You added http(s):// in the config file. Don't do that.")
    except SSLError as e:
        logger.error('Either your host is unreachable or you have an SSL issue. : %s', e)
    except ConnectionError as e:
        logger.error('Cannot resolve the url/ip/port. Check connectivity. Error: %s', e)
    except ChunkedEncodingError as e:
        logger.error('Broken connection during request... oops? Error: %s', e)

    return return_json 
开发者ID:Boerderij,项目名称:Varken,代码行数:39,代码来源:helpers.py

示例10: __init__

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def __init__(self):
        Analyzer.__init__(self)
        self.service = self.get_param(
            'config.service', None, 'Service parameter is missing')
        self.url = self.get_param('config.url', None, 'Missing API url')
        if self.url:
            self.url = self.url.rstrip('/')
        self.key = self.get_param('config.key', None, 'Missing API key')
        self.pwd = self.get_param('config.pwd', None, 'Missing API password')
        self.verify = self.get_param('config.verify', True)
        if not self.verify:
            requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
        self.proxies = self.get_param('config.proxy', None) 
开发者ID:TheHive-Project,项目名称:Cortex-Analyzers,代码行数:15,代码来源:ibmxforce_lookup.py

示例11: request_http

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def request_http(url):
  
  # setup request, insecurely
  headers = {'Authorization': 'NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA='}
  requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)

  request = requests.get(url, headers=headers, verify=False)
  
  if request.status_code not in [401, 302]:
    print('[!] Expecting response code 401 or 302, received: {}'.format(request.status_code))
    return None
  
  # get auth header
  auth_header = request.headers.get('WWW-Authenticate')
  
  if not auth_header:
    print('[!] NTLM Challenge response not found (WWW-Authenticate header missing)')
    return None

  if not 'NTLM' in auth_header:
    print('[!] NTLM Challenge response not found (WWW-Authenticate does not contain "NTLM")')
    return None

  # get challenge message from header
  challenge_message = base64.b64decode(auth_header.split(' ')[1].replace(',', ''))

  return challenge_message 
开发者ID:b17zr,项目名称:ntlm_challenger,代码行数:29,代码来源:ntlm_challenger.py

示例12: __init__

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def __init__(self):
        # Session ignoring SSL verify requests
        session = requests.Session()
        session.verify = False
        urllib3.disable_warnings(InsecureRequestWarning)

        self.__session = session
        self.__host = None
        self.__user = None
        self.__session_id = None 
开发者ID:globocom,项目名称:azkaban-cli,代码行数:12,代码来源:azkaban.py

示例13: perform_kubelet_query

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def perform_kubelet_query(self, url, verbose=True, timeout=10, stream=False):
        """
        Perform and return a GET request against kubelet. Support auth and TLS validation.
        """
        with disable_warnings_ctx(InsecureRequestWarning, disable=not self.kubelet_credentials.verify()):
            return requests.get(
                url,
                timeout=timeout,
                verify=self.kubelet_credentials.verify(),
                cert=self.kubelet_credentials.cert_pair(),
                headers=self.kubelet_credentials.headers(url),
                params={'verbose': verbose},
                stream=stream,
            ) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:16,代码来源:kubelet.py

示例14: test_silent_tls_warning

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def test_silent_tls_warning(monkeypatch, aggregator):
    check = KubeletCheck('kubelet', {}, [{}])
    check.kube_health_url = "https://example.com/"
    check.kubelet_credentials = KubeletCredentials({'verify_tls': 'false'})
    with pytest.warns(None) as record:
        check._perform_kubelet_check([])

    assert all(not issubclass(warning.category, InsecureRequestWarning) for warning in record) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:10,代码来源:test_kubelet.py

示例15: handle_tls_warning

# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import InsecureRequestWarning [as 别名]
def handle_tls_warning(self):
        with disable_warnings_ctx(InsecureRequestWarning, disable=True):
            yield 
开发者ID:DataDog,项目名称:integrations-core,代码行数:5,代码来源:http.py


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