當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib3.disable_warnings方法代碼示例

本文整理匯總了Python中urllib3.disable_warnings方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib3.disable_warnings方法的具體用法?Python urllib3.disable_warnings怎麽用?Python urllib3.disable_warnings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib3的用法示例。


在下文中一共展示了urllib3.disable_warnings方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_setcookie_language_value

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def get_setcookie_language_value(tgtUrl,timeout):

    urllib3.disable_warnings()
    tgtUrl = tgtUrl
    try:
        rsp = requests.get(tgtUrl, timeout=timeout, verify=False)
        rsp_setcookie = rsp.headers['Set-Cookie']
        # print rsp.text
        pattern = re.compile(r'(.*?)language=')
        language_pattern = pattern.findall(rsp_setcookie)
        setcookie_language = language_pattern[0].split(' ')[-1].strip() + 'language=en'
        return str(setcookie_language)

    except:
        print str(tgtUrl) + ' get setcookie language value error!'
        return 'get-setcookie-language-value-error' 
開發者ID:theLSA,項目名稱:discuz-ml-rce,代碼行數:18,代碼來源:dz-ml-rce.py

示例2: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def __init__(self):
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        requests.packages.urllib3.disable_warnings()

        self.timeout = TIMEOUT
        self.session = requests.Session()
        self.headers = get_ua()

        if COOKIE == 'random':
            plain = ''.join([random.choice('0123456789') for _ in range(8)])
            md5sum = hashlib.md5()
            md5sum.update(plain.encode('utf-8'))
            md5 = md5sum.hexdigest()
            self.headers.update({'Cookie': 'SESSION=' + md5})
        else:
            self.headers.update(COOKIE)

        if SOCKS5:
            ip, port = SOCKS5
            socks.set_default_proxy(socks.SOCKS5, ip, port)
            socket.socket = socks.socksocket 
開發者ID:al0ne,項目名稱:Vxscan,代碼行數:23,代碼來源:Requests.py

示例3: new_recipe

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def new_recipe(requests_session, action_id, server, headers):
    urllib3.disable_warnings()

    # Create a recipe
    recipe_data = {
        "action_id": action_id,
        "arguments": '{"learnMoreMessage":"This field may not be blank.","learnMoreUrl":"This field may not be blank.","message":"This field may not be blank.","postAnswerUrl":"This field may not be blank.","surveyId":"'
        + str(uuid.uuid4())
        + '","thanksMessage":"This field may not be blank."}',
        "name": "test recipe",
        "extra_filter_expression": "counter == 0",
        "enabled": "false",
    }

    response = requests_session.post(
        urljoin(server, "/api/v3/recipe/"), data=recipe_data, headers=headers
    )
    data = response.json()
    return {"id": data["id"], "latest_revision_id": data["latest_revision"]["id"]} 
開發者ID:mozilla,項目名稱:normandy,代碼行數:21,代碼來源:helpers.py

示例4: client

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def client(self):
        cls = self.__class__
        if cls._client is None:
            if self.verify_ssl is False:
                import requests
                requests.packages.urllib3.disable_warnings()
                import urllib3
                urllib3.disable_warnings()

            if self.username and self.password:
                self.log.debug("Creating Kubernetes client from username and password")
                cls._client = KubernetesClient.from_username_password(self.host, self.username, self.password,
                                                                      verify_ssl=self.verify_ssl)
            else:
                self.log.debug("Creating Kubernetes client from Service Account")
                cls._client = KubernetesClient.from_service_account(self.host, verify_ssl=self.verify_ssl)
        return cls._client 
開發者ID:danielfrg,項目名稱:jupyterhub-kubernetes_spawner,代碼行數:19,代碼來源:spawner.py

示例5: configure_logging

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def configure_logging():
    logging.basicConfig(
        level=logging.INFO,
        format='%(asctime)s - %(process)d - [%(levelname)s] %(message)s',
    )

    # Suppress boto INFO.
    logging.getLogger('boto3').setLevel(logging.WARNING)
    logging.getLogger('botocore').setLevel(logging.WARNING)
    logging.getLogger('nose').setLevel(logging.WARNING)

    logging.getLogger("requests").setLevel(logging.WARNING)
    logging.getLogger("urllib3").setLevel(logging.WARNING)

    import urllib3
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    # import botocore.vendored.requests.packages.urllib3 as urllib3
    urllib3.disable_warnings(botocore.vendored.requests.packages.urllib3.exceptions.InsecureRequestWarning) 
開發者ID:andresriancho,項目名稱:enumerate-iam,代碼行數:21,代碼來源:main.py

示例6: send

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def send(self, url, method="GET", payload=None, headers=None, cookies=None):
        # requests session
        output = Services.get('output')
        request = Session()
        prepped=self.prepare_request(url,method,payload,headers,cookies)
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        try:
            resp=request.send(
                prepped,
                timeout=self.timeout,
                proxies={
                    'http': self.proxy,
                    'https': self.proxy,
                    'ftp': self.proxy,
                },
                allow_redirects=self.redirect,
                verify=False)
            return resp
        except TimeoutError:
            output.error("Timeout error on the URL: %s" % url)
        except RequestException as err:
            output.error("Error while trying to contact the website: \n {0}\n".format(err))
            raise(err) 
開發者ID:shenril,項目名稱:Sitadel,代碼行數:25,代碼來源:request.py

示例7: get_e2e_configuration

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def get_e2e_configuration():
    config = Configuration()
    config.host = None
    if os.path.exists(
            os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)):
        kube_config.load_kube_config(client_configuration=config)
    else:
        print('Unable to load config from %s' %
              kube_config.KUBE_CONFIG_DEFAULT_LOCATION)
        for url in ['https://%s:8443' % DEFAULT_E2E_HOST,
                    'http://%s:8080' % DEFAULT_E2E_HOST]:
            try:
                urllib3.PoolManager().request('GET', url)
                config.host = url
                config.verify_ssl = False
                urllib3.disable_warnings()
                break
            except urllib3.exceptions.HTTPError:
                pass
    if config.host is None:
        raise unittest.SkipTest('Unable to find a running Kubernetes instance')
    print('Running test against : %s' % config.host)
    config.assert_hostname = False
    return config 
開發者ID:kubernetes-client,項目名稱:python,代碼行數:26,代碼來源:base.py

示例8: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def __init__(self, url, user_agent, cookies_string=False, custom_header=False, insecure_ssl='false', proxy=False):
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        self.__url = url
        self.__headers = dict()
        self.__headers['User-Agent'] = self.__default_user_agent if user_agent == 'default' else user_agent
        if cookies_string:
            self.__headers['Cookie'] = cookies_string
        if custom_header:
            self.__parse_custom_header(custom_header)
        self.__verify = 'CERT_REQUIRED' if insecure_ssl == 'false' else 'CERT_NONE'
        if proxy:
            proxy_type = proxy.split('://')[0]
            if proxy_type == 'http' or proxy_type == 'https':
                self.__request_obj = urllib3.ProxyManager(proxy, ssl_version=ssl.PROTOCOL_TLSv1,
                                                          timeout=self.__request_timeout, cert_reqs=self.__verify)
            else:
                self.__request_obj = SOCKSProxyManager(proxy, ssl_version=ssl.PROTOCOL_TLSv1,
                                                       timeout=self.__request_timeout, cert_reqs=self.__verify)
        else:
            self.__request_obj = urllib3.PoolManager(ssl_version=ssl.PROTOCOL_TLSv1, timeout=self.__request_timeout,
                                                     cert_reqs=self.__verify)
        # print (vars(self)) 
開發者ID:antonioCoco,項目名稱:SharPyShell,代碼行數:24,代碼來源:Request.py

示例9: send_turing

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def send_turing(key, info, userid):
    """
    send request to Turing robot, and get a response
    :param key: TURING_KEY
    :param info: the message from user
    :param userid: chat_id, for context parse
    :return: response from Turing Bot, in text.
    """
    return requests.get(' http://115.159.180.177:6789/chat?text={}'.format(info)).json()['text']

    data = {
        "key": key,
        "info": info,
        "userid": userid

    }

    # TODO: use local cert to prevent from MITM, worst idea ever.
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    url = 'https://www.tuling123.com/openapi/api'
    result = requests.post(url, json=data, verify=False).text
    return json.loads(result).get('text') 
開發者ID:BennyThink,項目名稱:ExpressBot,代碼行數:24,代碼來源:turing.py

示例10: grimoire_con

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def grimoire_con(insecure=True, conn_retries=MAX_RETRIES_ON_CONNECT, total=MAX_RETRIES):
    conn = requests.Session()
    # {backoff factor} * (2 ^ ({number of total retries} - 1))
    # conn_retries = 21  # 209715.2 = 2.4d
    # total covers issues like 'ProtocolError('Connection aborted.')
    # Retry when there are errors in HTTP connections
    retries = urllib3.util.Retry(total=total, connect=conn_retries, read=MAX_RETRIES_ON_READ,
                                 redirect=MAX_RETRIES_ON_REDIRECT, backoff_factor=BACKOFF_FACTOR,
                                 method_whitelist=False, status_forcelist=STATUS_FORCE_LIST)
    adapter = requests.adapters.HTTPAdapter(max_retries=retries)
    conn.mount('http://', adapter)
    conn.mount('https://', adapter)

    if insecure:
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        conn.verify = False

    return conn 
開發者ID:chaoss,項目名稱:grimoirelab-elk,代碼行數:20,代碼來源:utils.py

示例11: wait_for_workflow_execution

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def wait_for_workflow_execution(self, workflow_execution, wait_seconds):
        headers = {"Authorization": self.env_vars['token']}

        # disable unsigned HTTPS certificate warnings
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

        workflow_id = workflow_execution['Id']

        # It might take a few seconds for the step function to start, so we'll try to get the execution arn a few times
        # before giving up
        retries=0
        # FIXME retry_limit = ceil(wait_seconds/5)
        retry_limit = 60
        while(retries<retry_limit):
            retries+=1
            print("Checking workflow execution status for workflow {}".format(workflow_id))
            workflow_execution_response = requests.get(self.stack_resources["WorkflowApiEndpoint"]+'/workflow/execution/'+workflow_id, verify=False, headers=headers)
            workflow_execution = workflow_execution_response.json()
            assert workflow_execution_response.status_code == 200
            if workflow_execution["Status"] in ["Complete", "Error"]:
                break
            time.sleep(5)

        return workflow_execution 
開發者ID:awslabs,項目名稱:aws-media-insights-engine,代碼行數:26,代碼來源:conftest.py

示例12: operations

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def operations(api, session_operation_configs, api_schema):
    api = api()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Creating test operations")
    for config in session_operation_configs:

        print("\nOPERATION CONFIGURATION: {}".format(config))

        # Create the operation
        create_operation_response = api.create_operation_request(config)
        operation = create_operation_response.json()
        assert create_operation_response.status_code == 200
        validation.schema(operation, api_schema["create_operation_response"])

    # yield session_operation_configs

    # for config in session_operation_configs:
    #     #Delete the operation
    #     operation = {}
    #     operation["Name"] = config["Name"]

    #     delete_operation_response = api.delete_operation_request(operation)
    #     assert delete_operation_response.status_code == 200 
開發者ID:awslabs,項目名稱:aws-media-insights-engine,代碼行數:26,代碼來源:conftest.py

示例13: stages

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def stages(api, operations, session_stage_configs, api_schema):
    api = api()
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

    print("Creating test stages")
    for config in session_stage_configs:

        print("\nSTAGE CONFIGURATION: {}".format(config))

        # Create the stage
        create_stage_response = api.create_stage_request(config)
        stage = create_stage_response.json()

        assert create_stage_response.status_code == 200
        validation.schema(stage, api_schema["create_stage_response"])

    # yield session_stage_configs

    # for config in session_stage_configs:
    #     #Delete the stage
    #     stage = {}
    #     stage["Name"] = config["Name"]

    #     delete_stage_response = api.delete_stage_request(stage)
    #     assert delete_stage_response.status_code == 200 
開發者ID:awslabs,項目名稱:aws-media-insights-engine,代碼行數:27,代碼來源:conftest.py

示例14: do_url_request

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def do_url_request(self, url, body=None, method='GET'):
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        currentHeaders = self.contentTypeHeaders

        try:
            if method == 'GET':
                res = requests.get(url, headers=currentHeaders, verify=False, timeout=2)
            elif method == 'POST':
                res = requests.post(url, data=body, headers=currentHeaders, verify=False)
            else:
                raise ValueError("Method %s is not supported right now." % method)

            self.response = res.status_code
            content = res.text
        except Exception:
            print("Can't perform request to %s" % (url))
            return ""

        return content 
開發者ID:opentaps,項目名稱:opentaps_seas,代碼行數:21,代碼來源:client.py

示例15: _generate_audio_file

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import disable_warnings [as 別名]
def _generate_audio_file(self):
        """
        Generic method used as a Callback in TTSModule
            - must provided the audio file and write it on the disk

        .. raises:: FailToLoadSoundFile
        """

        # Since the gTTS lib disabled the SSL verification we get rid of insecure request warning
        urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
        
        tts = gTTS(text=self.words, lang=self.language)
        
        # OK we get the audio we can write the sound file
        tts.save(self.file_path)
        
        # Re enable the warnings to avoid affecting the whole kalliope process 
        warnings.resetwarnings() 
開發者ID:kalliope-project,項目名稱:kalliope,代碼行數:20,代碼來源:googletts.py


注:本文中的urllib3.disable_warnings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。