本文整理汇总了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'
示例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
示例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"]}
示例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
示例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)
示例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)
示例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
示例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))
示例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')
示例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
示例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
示例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
示例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
示例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
示例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()