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


Python client.HTTPSConnection方法代碼示例

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


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

示例1: validate_optional_args

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def validate_optional_args(args):
	"""Check if an argument was provided that depends on a module that may
	not be part of the Python standard library.

	If such an argument is supplied, and the module does not exist, exit
	with an error stating which module is missing.
	"""
	optional_args = {
		'json': ('json/simplejson python module', json),
		'secure': ('SSL support', HTTPSConnection),
	}

	for arg, info in optional_args.items():
		if getattr(args, arg, False) and info[1] is None:
			raise SystemExit('%s is not installed. --%s is '
							 'unavailable' % (info[0], arg)) 
開發者ID:NatanaelAntonioli,項目名稱:L.E.S.M.A,代碼行數:18,代碼來源:L.E.S.M.A. - Fabrica de Noobs Speedtest.py

示例2: httpPost

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def httpPost(self, url, resource, params ):
        headers = {
            "Accept": "application/json",
            'Content-Type': 'application/x-www-form-urlencoded',
            "User-Agent": "Chrome/39.0.2171.71",
            "KEY":self.accessKey,
            "SIGN":self.getSign(params, self.secretKey)
        }

        conn = httplib.HTTPSConnection(url, timeout=10 )
        tempParams = urllib.parse.urlencode(params) if params else ''

        conn.request("POST", resource, tempParams, headers)
        response = conn.getresponse()
        data = response.read().decode('utf-8')

        conn.close()
        return json.loads(data)

    #---------------------------------------------------------------------- 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:22,代碼來源:vngate.py

示例3: http

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def http(method, url, body=None, headers=None):
    url_info = urlparse.urlparse(url)
    if url_info.scheme == "https":
        con = httplib.HTTPSConnection(url_info.hostname, url_info.port or 443)
    else:
        con = httplib.HTTPConnection(url_info.hostname, url_info.port or 80)

    con.request(method, url_info.path, body, headers)
    response = con.getresponse()

    try:
        if 400 <= response.status < 500:
            raise HttpClientError(response.status, response.reason,
                                  response.read())
        elif 500 <= response.status < 600:
            raise HttpServerError(response.status, response.reason,
                                  response.read())
        else:
            yield response
    finally:
        con.close() 
開發者ID:clarkerubber,項目名稱:irwin,代碼行數:23,代碼來源:fishnet.py

示例4: __init__

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def __init__(self, moodle_domain: str, moodle_path: str = '/',
                 token: str = '', skip_cert_verify=False):
        """
        Opens a connection to the Moodle system
        """
        if skip_cert_verify:
            context = ssl._create_unverified_context()
        else:
            context = ssl.create_default_context(cafile=certifi.where())
        self.connection = HTTPSConnection(moodle_domain, context=context)

        self.token = token
        self.moodle_domain = moodle_domain
        self.moodle_path = moodle_path

        RequestHelper.stdHeader = {
            'User-Agent': ('Mozilla/5.0 (X11; Linux x86_64)' +
                           ' AppleWebKit/537.36 (KHTML, like Gecko)' +
                           ' Chrome/78.0.3904.108 Safari/537.36'),
            'Content-Type': 'application/x-www-form-urlencoded'
        } 
開發者ID:C0D3D3V,項目名稱:Moodle-Downloader-2,代碼行數:23,代碼來源:request_helper.py

示例5: __make_request

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def __make_request(self, url, params):
        parse_result = urlparse(url)
        hostname = parse_result.netloc
        context = ssl.SSLContext()
        conn = HTTPSConnection(hostname, None, context=context)
        conn.connect()
        body = urlencode(params)
        headers = {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': len(body),
        }
        request_url = f"{parse_result.path}?{parse_result.query}"
        try:
            conn.request("POST", request_url, body, headers)
            response = conn.getresponse()
            data = response.read()
        finally:
            conn.close()
        return data 
開發者ID:djudman,項目名稱:evernote-telegram-bot,代碼行數:21,代碼來源:api.py

示例6: get_dex_auth_token

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def get_dex_auth_token(address, port, auth_dict, ca_cert_path, proxy_host=None, proxy_port=None,
                       insecure=False, offline=False):
    conn = None
    context = create_security_context(ca_cert_path, insecure=insecure)
    if proxy_host:
        conn = httplib.HTTPSConnection(proxy_host, proxy_port, context=context)
        conn.set_tunnel(address, port)
    else:
        conn = httplib.HTTPSConnection(address, port, context=context)
    headers = {"Content-type": "application/json", "Accept": "text/plain"}
    url = "/authenticate/token?offline=True" if offline else "/authenticate/token"
    conn.request("POST", url, json.dumps(auth_dict), headers)
    response = conn.getresponse()
    data = response.read()
    if response.status == 200:
        dict_data = json.loads(data.decode('utf-8'))
        return dict_data['data']['token']
    else:
        print("Error occurred while trying to get token.")
        sys.exit() 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:22,代碼來源:common_token.py

示例7: get_dex_auth_url

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def get_dex_auth_url(address, port, ca_cert_path=None, proxy_host=None, proxy_port=None,
                     insecure=False, offline=False):
    conn = None
    context = create_security_context(ca_cert_path, insecure=insecure)
    if proxy_host:
        conn = httplib.HTTPSConnection(proxy_host, proxy_port, context=context)
        conn.set_tunnel(address, port)
    else:
        conn = httplib.HTTPSConnection(address, port, context=context)
    url = "/authenticate?offline=True" if offline else "/authenticate"
    conn.request("GET", url)
    r1 = conn.getresponse()
    dex_auth_url = r1.getheader('location')
    if dex_auth_url is None:
        print("Can`t get dex url.")
        sys.exit()
    return dex_auth_url 
開發者ID:IntelAI,項目名稱:inference-model-manager,代碼行數:19,代碼來源:common_token.py

示例8: _send_response

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def _send_response(response_url, response_body):
    try:
        json_response_body = json.dumps(response_body)
    except Exception as e:
        msg = "Failed to convert response to json: {}".format(str(e))
        logger.error(msg, exc_info=True)
        response_body = {'Status': 'FAILED', 'Data': {}, 'Reason': msg}
        json_response_body = json.dumps(response_body)
    logger.debug("CFN response URL: {}".format(response_url))
    logger.debug(json_response_body)
    headers = {'content-type': '', 'content-length': str(len(json_response_body))}
    split_url = urlsplit(response_url)
    host = split_url.netloc
    url = urlunsplit(("", "", *split_url[2:]))
    while True:
        try:
            connection = HTTPSConnection(host)
            connection.request(method="PUT", url=url, body=json_response_body, headers=headers)
            response = connection.getresponse()
            logger.info("CloudFormation returned status code: {}".format(response.reason))
            break
        except Exception as e:
            logger.error("Unexpected failure sending response to CloudFormation {}".format(e), exc_info=True)
            time.sleep(5) 
開發者ID:aws-cloudformation,項目名稱:custom-resource-helper,代碼行數:26,代碼來源:utils.py

示例9: validate_optional_args

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def validate_optional_args(args):
    """Check if an argument was provided that depends on a module that may
    not be part of the Python standard library.

    If such an argument is supplied, and the module does not exist, exit
    with an error stating which module is missing.
    """
    optional_args = {
        'json': ('json/simplejson python module', json),
        'secure': ('SSL support', HTTPSConnection),
    }

    for arg, info in optional_args.items():
        if getattr(args, arg, False) and info[1] is None:
            raise SystemExit('%s is not installed. --%s is '
                             'unavailable' % (info[0], arg)) 
開發者ID:PaperDashboard,項目名稱:shadowsocks,代碼行數:18,代碼來源:speedtest.py

示例10: request_oneview

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def request_oneview(oneview_ip, rest_url):
    try:
        connection = HTTPSConnection(
            oneview_ip, context=ssl.SSLContext(ssl.PROTOCOL_TLSv1_2))

        connection.request(
            method='GET', url=rest_url,
            headers={'Content-Type': 'application/json',
                     'X-API-Version': config.get_api_version()}
            )

        response = connection.getresponse()

        if response.status != status.HTTP_200_OK:
            message = "OneView is unreachable at {}".format(
                oneview_ip)
            raise OneViewRedfishException(message)

        text_response = response.read().decode('UTF-8')
        json_response = json.loads(text_response)

        return json_response
    finally:
        connection.close() 
開發者ID:HewlettPackard,項目名稱:oneview-redfish-toolkit,代碼行數:26,代碼來源:connection.py

示例11: __init__

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def __init__(self, proxytype, proxyaddr, proxyport=None, rdns=True, username=None, password=None, *args, **kwargs):
        self.proxyargs = (proxytype, proxyaddr, proxyport, rdns, username, password)
        httplib.HTTPSConnection.__init__(self, *args, **kwargs) 
開發者ID:vulscanteam,項目名稱:vulscan,代碼行數:5,代碼來源:sockshandler.py

示例12: plugin

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def plugin(srv, item):
    srv.logging.debug("*** MODULE=%s: service=%s, target=%s", __file__, item.service, item.target)

    apikey = item.addrs[0]

    title = item.get('title', srv.SCRIPTNAME)
    message = item.message

    http_handler = HTTPSConnection("pushalot.com")

    data = {'AuthorizationToken': apikey,
            'Title': title.encode('utf-8'),
            'Body': message.encode('utf-8')
            }

    try:
        http_handler.request("POST", "/api/sendmessage",
                             headers={'Content-type': "application/x-www-form-urlencoded"},
                             body=urlencode(data)
                             )
    except (SSLError, HTTPException) as e:
        srv.logging.warn("Pushalot notification failed: %s" % str(e))
        return False

    response = http_handler.getresponse()

    srv.logging.debug("Reponse: %s, %s" % (response.status, response.reason))

    return True 
開發者ID:jpmens,項目名稱:mqttwarn,代碼行數:31,代碼來源:pushalot.py

示例13: get_https_connection

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def get_https_connection(self, host, timeout=300):
            """Returns a HTTPSConnection"""
            return HTTPSConnection(
                host,
                key_file=self._ssl_config['key'],
                cert_file=self._ssl_config['cert']
            ) 
開發者ID:LuciferJack,項目名稱:python-mysql-pool,代碼行數:9,代碼來源:connection.py

示例14: __init__

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def __init__(self, HTTPConnection=httplib.HTTPConnection,
                 HTTPSConnection=httplib.HTTPSConnection):
        self.HTTPConnection = HTTPConnection
        self.HTTPSConnection = HTTPSConnection 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:6,代碼來源:client.py

示例15: _timeout_supported

# 需要導入模塊: from http import client [as 別名]
# 或者: from http.client import HTTPSConnection [as 別名]
def _timeout_supported(self, ConnClass):
        if sys.version_info < (2, 7) and ConnClass in (
            httplib.HTTPConnection, httplib.HTTPSConnection): # pragma: no cover
            return False
        return True 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:7,代碼來源:client.py


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