Python certifi.where() Examples
The following are 30
code examples of certifi.where().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
certifi
, or try the search function
.
Example #1
Source File: homura.py From homura with BSD 2-Clause "Simplified" License | 7 votes |
def _fill_in_cainfo(self): """Fill in the path of the PEM file containing the CA certificate. The priority is: 1. user provided path, 2. path to the cacert.pem bundle provided by certifi (if installed), 3. let pycurl use the system path where libcurl's cacert bundle is assumed to be stored, as established at libcurl build time. """ if self.cainfo: cainfo = self.cainfo else: try: cainfo = certifi.where() except AttributeError: cainfo = None if cainfo: self._pycurl.setopt(pycurl.CAINFO, cainfo)
Example #2
Source File: http.py From Sony-PMCA-RE with MIT License | 6 votes |
def request(url, data=None, headers={}, cookies={}, auth=None): if cookies: headers['Cookie'] = '; '.join(quote(k) + '=' + quote(v) for (k, v) in cookies.items()) request = Request(str(url), data, headers) manager = HTTPPasswordMgrWithDefaultRealm() if auth: manager.add_password(None, request.get_full_url(), auth[0], auth[1]) handlers = [HTTPBasicAuthHandler(manager), HTTPDigestAuthHandler(manager)] try: import certifi, ssl handlers.append(HTTPSHandler(context=ssl.create_default_context(cafile=certifi.where()))) except: # App engine pass response = build_opener(*handlers).open(request) cj = CookieJar() cj.extract_cookies(response, request) headers = dict(response.headers) raw_contents = response.read() contents = raw_contents.decode(headers.get('charset', 'latin1')) return HttpResponse(urlparse(response.geturl()), contents, raw_contents, headers, dict((c.name, c.value) for c in cj))
Example #3
Source File: certifi.py From IkaLog with Apache License 2.0 | 6 votes |
def where(): cacert_pem = IkaUtils.get_path('cacert.pem') if os.path.exists(cacert_pem): return cacert_pem try: import certifi cacert_pem = certifi.where() if os.path.exists(cacert_pem): return cacert_pem except ImportError: pass try: import requests.certs cacert_pem = requests.certs.where() if os.path.exists(cacert_pem): return cacert_pem except ImportError: pass IkaUtils.dprint('ikalog.utils.Certifi: Cannot find any cacert.pem') return None
Example #4
Source File: fetch_service_config.py From endpoints-tools with Apache License 2.0 | 6 votes |
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
Example #5
Source File: fetch_service_config.py From endpoints-tools with Apache License 2.0 | 6 votes |
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
Example #6
Source File: client.py From grpclib with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _get_default_ssl_context(self) -> '_ssl.SSLContext': if _ssl is None: raise RuntimeError('SSL is not supported.') try: import certifi except ImportError: cafile = None else: cafile = certifi.where() ctx = _ssl.create_default_context( purpose=_ssl.Purpose.SERVER_AUTH, cafile=cafile, ) ctx.options |= (_ssl.OP_NO_TLSv1 | _ssl.OP_NO_TLSv1_1) ctx.set_ciphers('ECDHE+AESGCM:ECDHE+CHACHA20:DHE+AESGCM:DHE+CHACHA20') ctx.set_alpn_protocols(['h2']) try: ctx.set_npn_protocols(['h2']) except NotImplementedError: pass return ctx
Example #7
Source File: fetch_service_config.py From endpoints-tools with Apache License 2.0 | 6 votes |
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
Example #8
Source File: api.py From python-sensor with MIT License | 6 votes |
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())
Example #9
Source File: junglescam.py From JungleScam with MIT License | 6 votes |
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
Example #10
Source File: wfapi.py From terraform-templates with Apache License 2.0 | 6 votes |
def _certifi_ssl_context(self): if (sys.version_info.major == 2 and sys.hexversion >= 0x02070900 or sys.version_info.major == 3 and sys.hexversion >= 0x03040300): where = certifi.where() self._log(DEBUG1, 'certifi %s: %s', certifi.__version__, where) return ssl.create_default_context( purpose=ssl.Purpose.SERVER_AUTH, cafile=where) else: return None # # XXX USE OF cloud_ssl_context() IS DEPRECATED! # # If your operating system certificate store is out of date you can # install certifi (https://pypi.python.org/pypi/certifi) and its CA # bundle will be used for SSL server certificate verification when # ssl_context is None. #
Example #11
Source File: common.py From azure-uamqp-python with MIT License | 6 votes |
def set_tlsio(self, hostname, port): """Setup the default underlying TLS IO layer. On Windows this is Schannel, on Linux and MacOS this is OpenSSL. :param hostname: The endpoint hostname. :type hostname: bytes :param port: The TLS port. :type port: int """ _default_tlsio = c_uamqp.get_default_tlsio() _tlsio_config = c_uamqp.TLSIOConfig() _tlsio_config.hostname = hostname _tlsio_config.port = int(port) _underlying_xio = c_uamqp.xio_from_tlsioconfig(_default_tlsio, _tlsio_config) # pylint: disable=attribute-defined-outside-init cert = self.cert_file or certifi.where() with open(cert, 'rb') as cert_handle: cert_data = cert_handle.read() try: _underlying_xio.set_certificates(cert_data) except ValueError: _logger.warning('Unable to set external certificates.') self.sasl_client = _SASLClient(_underlying_xio, self.sasl) # pylint: disable=attribute-defined-outside-init self.consumed = False # pylint: disable=attribute-defined-outside-init
Example #12
Source File: cooljugator_scraper.py From mlconjug with MIT License | 6 votes |
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()
Example #13
Source File: get_functions.py From kawaii-player with GNU General Public License v3.0 | 5 votes |
def get_ca_certificate(): ca_cert = '' if os.name == 'nt': try: import certifi ca_cert = certifi.where() except Exception as e: print(e) return ca_cert
Example #14
Source File: btcprice.py From OpenBazaar-Server with MIT License | 5 votes |
def dictForUrl(url): request = Request(url) result = urlopen(request, cafile=certifi.where(), timeout=5).read() return json.loads(result)
Example #15
Source File: certs.py From oss-ftp with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #16
Source File: certs.py From oss-ftp with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #17
Source File: elasticsearch.py From lego with MIT License | 5 votes |
def set_up(self): host = getattr(settings, "ELASTICSEARCH", None) if host: self.connection = Elasticsearch( settings.ELASTICSEARCH, ca_certs=certifi.where() )
Example #18
Source File: utils.py From mlconjug with MIT License | 5 votes |
def get_tor_session(self): """ Configures and create the session to use a Tor Socks proxy. :return: urllib3.SOCKSProxyManager object. """ 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'} session = SOCKSProxyManager('socks5://{0}:{1}'.format(self.ip, self.socksport), cert_reqs='CERT_REQUIRED', ca_certs=certifi.where(), headers=user_agent) return session
Example #19
Source File: junglescam.py From JungleScam with MIT License | 5 votes |
def getRandomUA(): _httpPool = urllib3.PoolManager( 1, cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) url = "https://fake-useragent.herokuapp.com/browsers/0.1.8" r = _httpPool.request('GET', url).data.decode('utf-8') browsers = loads(r)['browsers'] return browsers
Example #20
Source File: connection.py From aliyun-tablestore-python-sdk with MIT License | 5 votes |
def __init__(self, host, path, timeout=0, maxsize=50): self.host = host self.path = path self.pool = PoolManager( self.NUM_POOLS, headers=None, cert_reqs='CERT_REQUIRED', # Force certificate check ca_certs=certifi.where(), # Path to the Certifi bundle strict=True, # TODO more comments to explain these parameters timeout=timeout, maxsize=maxsize, block=True, )
Example #21
Source File: certs.py From Yuki-Chan-The-Auto-Pentest with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #22
Source File: rest.py From jupyterhub-kubernetes_spawner with Apache License 2.0 | 5 votes |
def __init__(self, pools_size=4): # urllib3.PoolManager will pass all kw parameters to connectionpool # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # ca_certs vs cert_file vs key_file # http://stackoverflow.com/a/23957365/2985775 # cert_reqs if Configuration().verify_ssl: cert_reqs = ssl.CERT_REQUIRED else: cert_reqs = ssl.CERT_NONE # ca_certs if Configuration().ssl_ca_cert: ca_certs = Configuration().ssl_ca_cert else: # if not set certificate file, use Mozilla's root certificates. ca_certs = certifi.where() # cert_file cert_file = Configuration().cert_file # key file key_file = Configuration().key_file # https pool manager self.pool_manager = urllib3.PoolManager( num_pools=pools_size, cert_reqs=cert_reqs, ca_certs=ca_certs, cert_file=cert_file, key_file=key_file )
Example #23
Source File: certs.py From SalesforceXyTools with Apache License 2.0 | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #24
Source File: certs.py From vnpy_crypto with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #25
Source File: certs.py From splunk-aws-project-trumpet with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #26
Source File: certs.py From splunk-aws-project-trumpet with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #27
Source File: certs.py From splunk-aws-project-trumpet with MIT License | 5 votes |
def where(): """Return the preferred certificate bundle.""" return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #28
Source File: certs.py From faces with GNU General Public License v2.0 | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #29
Source File: certs.py From faces with GNU General Public License v2.0 | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')
Example #30
Source File: certs.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def where(): """Return the preferred certificate bundle.""" # vendored bundle inside Requests return os.path.join(os.path.dirname(__file__), 'cacert.pem')