本文整理汇总了Python中requests.packages方法的典型用法代码示例。如果您正苦于以下问题:Python requests.packages方法的具体用法?Python requests.packages怎么用?Python requests.packages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests
的用法示例。
在下文中一共展示了requests.packages方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _new_session
# 需要导入模块: import requests [as 别名]
# 或者: from requests import packages [as 别名]
def _new_session(retry_timeout_config):
"""
Return a new `requests.Session` object.
"""
retry = requests.packages.urllib3.Retry(
total=None,
connect=retry_timeout_config.connect_retries,
read=retry_timeout_config.read_retries,
method_whitelist=retry_timeout_config.method_whitelist,
redirect=retry_timeout_config.max_redirects)
session = requests.Session()
session.mount('https://',
requests.adapters.HTTPAdapter(max_retries=retry))
session.mount('http://',
requests.adapters.HTTPAdapter(max_retries=retry))
return session
示例2: __init__
# 需要导入模块: import requests [as 别名]
# 或者: from requests import packages [as 别名]
def __init__(self, cloud_info, inf):
self.cloud = cloud_info
"""Data about the Cloud Provider."""
self.inf = inf
"""Infrastructure this CloudConnector is associated with."""
self.logger = logging.getLogger('CloudConnector')
"""Logger object."""
self.error_messages = ""
"""String with error messages to be shown to the user."""
self.verify_ssl = Config.VERIFI_SSL
"""Verify SSL connections """
if not self.verify_ssl:
# To avoid errors with host certificates
try:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
except Exception:
pass
try:
# To avoid annoying InsecureRequestWarning messages in some Connectors
import requests.packages
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
except Exception:
pass
示例3: __init__
# 需要导入模块: import requests [as 别名]
# 或者: from requests import packages [as 别名]
def __init__(self):
self.state = Session.STATE_INIT
self.credentials = None
self.session = None
self.auth = None
self.retrying = False # Avoid infinite loop when successful auth / unsuccessful query
# yuck suppress InsecurePlatformWarning under Python < 2.7.9 which lacks SNI support
if sys.version_info < (2,7,9):
from requests.packages import urllib3
urllib3.disable_warnings()
if getattr(sys, 'frozen', False):
os.environ['REQUESTS_CA_BUNDLE'] = join(config.respath, 'cacert.pem')
示例4: __init__
# 需要导入模块: import requests [as 别名]
# 或者: from requests import packages [as 别名]
def __init__(self, config=Config()):
""":type _config: :class:`Config`"""
self._config = config
self.session_id = None
self.user = None
self.country_code = 'US' # Enable Trial Mode
self.client_unique_key = None
try:
from requests.packages import urllib3
urllib3.disable_warnings() # Disable OpenSSL Warnings in URLLIB3
except:
pass
示例5: get_cloud_init_data
# 需要导入模块: import requests [as 别名]
# 或者: from requests import packages [as 别名]
def get_cloud_init_data(self, radl=None, vm=None, public_key=None, user=None):
"""
Get the cloud init data specified by the user in the RADL
"""
cloud_config = {}
if radl:
configure_name = None
if radl.contextualize.items:
system_name = radl.systems[0].name
for item in radl.contextualize.items.values():
if item.system == system_name and item.get_ctxt_tool() == "cloud_init":
configure_name = item.configure
if configure_name:
cloud_config = yaml.safe_load(radl.get_configure_by_name(configure_name).recipes)
if not isinstance(cloud_config, dict):
# The cloud_init data is a shell script
cloud_config = radl.get_configure_by_name(configure_name).recipes.strip()
self.log_debug(cloud_config)
return cloud_config
# Only for those VMs with private IP
if Config.SSH_REVERSE_TUNNELS and vm and not vm.hasPublicNet():
if 'packages' not in cloud_config:
cloud_config['packages'] = []
cloud_config['packages'].extend(["curl", "sshpass"])
curl_command = vm.get_boot_curl_commands()
if 'bootcmd' not in cloud_config:
cloud_config['bootcmd'] = []
cloud_config['bootcmd'].extend(curl_command)
if vm and vm.getSSHPort() != 22:
if 'bootcmd' not in cloud_config:
cloud_config['bootcmd'] = []
cloud_config['bootcmd'].append("sed -i '/Port 22/c\\Port %s' /etc/ssh/sshd_config" % vm.getSSHPort())
cloud_config['bootcmd'].append("service sshd restart")
if public_key:
user_data = {}
user_data['name'] = user
user_data['sudo'] = "ALL=(ALL) NOPASSWD:ALL"
user_data['lock-passwd'] = True
user_data['ssh-import-id'] = user
# avoid to use default /home dir
user_data['homedir'] = "/opt/%s" % user
user_data['ssh-authorized-keys'] = [public_key.strip()]
if 'users' not in cloud_config:
cloud_config['users'] = []
cloud_config['users'].append(user_data)
if cloud_config:
if 'merge_how' not in cloud_config:
cloud_config['merge_how'] = 'list(append)+dict(recurse_array,no_replace)+str()'
res = yaml.safe_dump(cloud_config, default_flow_style=False, width=512)
self.log_debug("#cloud-config\n%s" % res)
return "#cloud-config\n%s" % res
else:
return None