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


Python urllib3.PoolManager方法代碼示例

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


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

示例1: fetch_service_config_rollout_strategy

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def fetch_service_config_rollout_strategy(metadata):
    """Fetch service config rollout strategy from metadata URL."""
    url = metadata + _METADATA_PATH + "/attributes/" + \
        _METADATA_ROLLOUT_STRATEGY
    headers = {"Metadata-Flavor": "Google"}
    client = urllib3.PoolManager(ca_certs=certifi.where())
    try:
        response = client.request("GET", url, headers=headers)
    except:
        logging.info("Failed to fetch service config rollout strategy " + \
            "from the metadata server: " + url);
        return None
    status_code = response.status

    if status_code != 200:
        # Fetching rollout strategy is optional. No need to leave log
        return None

    rollout_strategy = response.data
    logging.info("Service config rollout strategy: " + rollout_strategy)
    return rollout_strategy 
開發者ID:cloudendpoints,項目名稱:endpoints-tools,代碼行數:23,代碼來源:fetch_service_config.py

示例2: fetch_service_name

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def fetch_service_name(metadata):
    """Fetch service name from metadata URL."""
    url = metadata + _METADATA_PATH + "/attributes/" + _METADATA_SERVICE_NAME
    headers = {"Metadata-Flavor": "Google"}
    client = urllib3.PoolManager(ca_certs=certifi.where())
    try:
        response = client.request("GET", url, headers=headers)
    except:
        raise FetchError(1,
            "Failed to fetch service name from the metadata server: " + url)
    status_code = response.status

    if status_code != 200:
        message_template = "Fetching service name failed (url {}, status code {})"
        raise FetchError(1, message_template.format(url, status_code))

    name = response.data
    logging.info("Service name: " + name)
    return name

# config_id from metadata is optional. Returns None instead of raising error 
開發者ID:cloudendpoints,項目名稱:endpoints-tools,代碼行數:23,代碼來源:fetch_service_config.py

示例3: fetch_access_token

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def fetch_access_token(metadata):
    """Fetch access token from metadata URL."""
    access_token_url = metadata + _METADATA_PATH + "/service-accounts/default/token"
    headers = {"Metadata-Flavor": "Google"}
    client = urllib3.PoolManager(ca_certs=certifi.where())
    try:
        response = client.request("GET", access_token_url, headers=headers)
    except:
        raise FetchError(1,
            "Failed to fetch access token from the metadata server: " + access_token_url)
    status_code = response.status

    if status_code != 200:
        message_template = "Fetching access token failed (url {}, status code {})"
        raise FetchError(1, message_template.format(access_token_url, status_code))

    token = json.loads(response.data)["access_token"]
    return token 
開發者ID:cloudendpoints,項目名稱:endpoints-tools,代碼行數:20,代碼來源:fetch_service_config.py

示例4: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def __init__(self, headers=None, retries=None, validate_certificate=True,
                 urlfetch_retries=True):
        if not urlfetch:
            raise AppEnginePlatformError(
                "URLFetch is not available in this environment.")

        if is_prod_appengine_mvms():
            raise AppEnginePlatformError(
                "Use normal urllib3.PoolManager instead of AppEngineManager"
                "on Managed VMs, as using URLFetch is not necessary in "
                "this environment.")

        warnings.warn(
            "urllib3 is using URLFetch on Google App Engine sandbox instead "
            "of sockets. To use sockets directly instead of URLFetch see "
            "https://urllib3.readthedocs.io/en/latest/reference/urllib3.contrib.html.",
            AppEnginePlatformWarning)

        RequestMethods.__init__(self, headers)
        self.validate_certificate = validate_certificate
        self.urlfetch_retries = urlfetch_retries

        self.retries = retries or Retry.DEFAULT 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:25,代碼來源:appengine.py

示例5: loadConfig

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def loadConfig(self):
        # self.conf has to be inited each time for reloading
        self.conf = configparser.ConfigParser(allow_no_value=True, delimiters=('=',),
                                              inline_comment_prefixes=('#',))
        self.conf.read(self.file)
        self.pools = []
        proxy_sections = [section for section in self.conf.sections()
                          if section.startswith('PROXY')]
        for section in proxy_sections:
            proxy = section.split()[1]
            self.pools.append(dict(proxy=proxy,
                                   pool=self.setProxyPool(proxy),
                                   patterns=list(self.conf[section].keys())))
        default_proxy = self.conf['GENERAL'].get('DefaultProxy')
        default_pool = (self.setProxyPool(default_proxy) if default_proxy else
                        [urllib3.PoolManager(num_pools=10, maxsize=8, timeout=self.timeout, **self.sslparams),
                         urllib3.PoolManager(num_pools=10, maxsize=8, timeout=self.timeout)])
        self.pools.append({'proxy': default_proxy, 'pool': default_pool, 'patterns': '*'})

        self.noverifylist = list(self.conf['SSL No-Verify'].keys())
        self.blacklist = list(self.conf['BLACKLIST'].keys())
        self.sslpasslist = list(self.conf['SSL Pass-Thru'].keys())
        self.bypasslist = list(self.conf['BYPASS URL'].keys()) 
開發者ID:wheever,項目名稱:ProxHTTPSProxyMII,代碼行數:25,代碼來源:ProxHTTPSProxy.py

示例6: __connect

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def __connect(self):
        num_pools = float(self.pool_size_total) / self.pool_size_per_route
        headers = {
            'User-Agent': 'python-pilosa/%s' % VERSION,
        }

        timeout = urllib3.Timeout(connect=self.connect_timeout, read=self.socket_timeout)
        client_options = {
            "num_pools": num_pools,
            "maxsize": self.pool_size_per_route,
            "block": True,
            "headers": headers,
            "timeout": timeout,
            "retries": self.retry_count,
        }
        if not self.tls_skip_verify:
            client_options["cert_reqs"] = "CERT_REQUIRED"
            client_options["ca_certs"] = self.tls_ca_certificate_path

        client = urllib3.PoolManager(**client_options)
        self.__client = client 
開發者ID:pilosa,項目名稱:python-pilosa,代碼行數:23,代碼來源:client.py

示例7: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def __init__(self, headers=None, retries=None, validate_certificate=True,
                 urlfetch_retries=True):
        if not urlfetch:
            raise AppEnginePlatformError(
                "URLFetch is not available in this environment.")

        if is_prod_appengine_mvms():
            raise AppEnginePlatformError(
                "Use normal urllib3.PoolManager instead of AppEngineManager"
                "on Managed VMs, as using URLFetch is not necessary in "
                "this environment.")

        warnings.warn(
            "urllib3 is using URLFetch on Google App Engine sandbox instead "
            "of sockets. To use sockets directly instead of URLFetch see "
            "https://urllib3.readthedocs.io/en/latest/contrib.html.",
            AppEnginePlatformWarning)

        RequestMethods.__init__(self, headers)
        self.validate_certificate = validate_certificate
        self.urlfetch_retries = urlfetch_retries

        self.retries = retries or Retry.DEFAULT 
開發者ID:LiangYuxuan,項目名稱:NEIE-Assistant,代碼行數:25,代碼來源:appengine.py

示例8: connection_from_pool_key

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def connection_from_pool_key(self, pool_key, request_context=None):
		# Copied from `urllib3` so that we continue to ensure that this will
		# call `_new_pool`
		with self.pools.lock:
			pool = self.pools.get(pool_key)
			if pool:
				return pool

			scheme = request_context['scheme']
			host = request_context['host']
			port = request_context['port']
			pool = self._new_pool(scheme, host, port, request_context=request_context)
			self.pools[pool_key] = pool
		return pool


# Override the lower-level `requests` adapter that invokes the `urllib3`
# PoolManager objects 
開發者ID:ipfs-shipyard,項目名稱:py-ipfs-http-client,代碼行數:20,代碼來源:requests_wrapper.py

示例9: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def __init__(self, tor_controller=None):
        if not self.__socket_is_patched():
            gevent.monkey.patch_socket()
        self.tor_controller = tor_controller
        if not self.tor_controller:
            retries = urllib3.Retry(35)
            user_agent = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'}
            self.session = urllib3.PoolManager(maxsize=35,
                                               cert_reqs='CERT_REQUIRED',
                                               ca_certs=certifi.where(),
                                               headers=user_agent,
                                               retries=retries)
        else:
            self.session = self.tor_controller.get_tor_session()
        self.__tor_status__()
        self.languages = self._get_all_languages() 
開發者ID:SekouD,項目名稱:mlconjug,代碼行數:18,代碼來源:cooljugator_scraper.py

示例10: _wait_for_serving_container

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def _wait_for_serving_container(serving_port):
    """
    Args:
        serving_port:
    """
    i = 0
    http = urllib3.PoolManager()

    endpoint_url = "http://localhost:%s/ping" % serving_port
    while True:
        i += 5
        if i >= HEALTH_CHECK_TIMEOUT_LIMIT:
            raise RuntimeError("Giving up, endpoint didn't launch correctly")

        logger.info("Checking if serving container is up, attempt: %s", i)
        _, code = _perform_request(endpoint_url, http)
        if code != 200:
            logger.info("Container still not up, got: %s", code)
        else:
            return

        time.sleep(5) 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:24,代碼來源:entities.py

示例11: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def __init__(self, config=None):
        """Initializes a LocalSageMakerRuntimeClient

        Args:
            config (dict): Optional configuration for this client. In particular only
                the local port is read.
        """
        try:
            import urllib3
        except ImportError as e:
            logging.error(_module_import_error("urllib3", "Local mode", "local"))
            raise e

        self.http = urllib3.PoolManager()
        self.serving_port = 8080
        self.config = config
        self.serving_port = get_config_value("local.serving_port", config) or 8080 
開發者ID:aws,項目名稱:sagemaker-python-sdk,代碼行數:19,代碼來源:local_session.py

示例12: pageRequest

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def pageRequest(url):
    global roundRobin
    proxy = SOCKSProxyManager('socks5://localhost:'+str(torPort),
        cert_reqs='CERT_REQUIRED',
        ca_certs=certifi.where(),
        headers={'user-agent': randomUserAgent(), 'Cookie': ''})
    http = urllib3.PoolManager( 1,
        cert_reqs='CERT_REQUIRED',
        ca_certs=certifi.where(),
        headers={'user-agent': randomUserAgent(), 'Cookie': ''})
    if roundRobin % 2:
        response = http.request('GET', url)
    else:
        if torSupport:
            response = proxy.request('GET', url)
        else:
            response = http.request('GET', url)
    roundRobin += 1
    if not roundRobin % 60:
        newTorIdentity()
    return response.data 
開發者ID:pielco11,項目名稱:JungleScam,代碼行數:23,代碼來源:junglescam.py

示例13: get_e2e_configuration

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [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

示例14: __init__

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def __init__(self, **kwds):
        for key in kwds:
            self.__dict__[key] = kwds[key]

        log.warn("APIClient: This APIClient will be removed in a future version of this package.  Please"
                 "migrate away as soon as possible.")

        if "INSTANA_API_TOKEN" in os.environ:
            self.api_token = os.environ["INSTANA_API_TOKEN"]

        if "INSTANA_BASE_URL" in os.environ:
            self.base_url = os.environ["INSTANA_BASE_URL"]

        if self.base_url is None or self.api_token is None:
            log.warn("APIClient: API token or Base URL not set.  No-op mode")
        else:
            self.api_key = "apiToken %s" % self.api_token
            self.headers = {'Authorization': self.api_key, 'User-Agent': 'instana-python-sensor v' + package_version()}
            self.http = urllib3.PoolManager(cert_reqs='CERT_REQUIRED',
                                            ca_certs=certifi.where()) 
開發者ID:instana,項目名稱:python-sensor,代碼行數:22,代碼來源:api.py

示例15: send_query

# 需要導入模塊: import urllib3 [as 別名]
# 或者: from urllib3 import PoolManager [as 別名]
def send_query(self):
        assert(self.url is not None)
        assert(type(self.url) is str)
        assert(self.query is not None)
        assert(type(self.query) is str)

        data = {
            'query': self.query
        }

        if self.variables is not None and type(self.variables) is dict:
            data['variables'] = self.variables

        encoded_data = json.dumps(data).encode('utf-8')

        http = urllib3.PoolManager()

        response = http.request(
            'POST',
            self.url,
            body=encoded_data,
            headers={
                'Accept': 'application/json',
                'Content-type': 'application/json'
            }
        )

        try:
            return json.loads(response.data.decode('utf-8'))
        except:
            return {
                'errors': [
                    {
                        'status': response.status,
                        'message': 'Failed to contact GraphQL endpoint. Is "{}" the correct URL?'.format(self.url)
                    }
                ]
            } 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:40,代碼來源:graphql.py


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