当前位置: 首页>>代码示例>>Python>>正文


Python Session.cert方法代码示例

本文整理汇总了Python中requests.Session.cert方法的典型用法代码示例。如果您正苦于以下问题:Python Session.cert方法的具体用法?Python Session.cert怎么用?Python Session.cert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests.Session的用法示例。


在下文中一共展示了Session.cert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: consulta_distribuicao_nfe

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
def consulta_distribuicao_nfe(certificado, **kwargs):
    if "xml" not in kwargs:
        kwargs['xml'] = xml_consulta_distribuicao_nfe(certificado, **kwargs)
    xml_send = kwargs["xml"]
    base_url = localizar_url(
        'NFeDistribuicaoDFe',  kwargs['estado'], kwargs['modelo'],
        kwargs['ambiente'])

    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    xml_um = etree.fromstring('<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/"><cUF>AN</cUF><versaoDados>1.00</versaoDados></nfeCabecMsg>')
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = next(iter(client.wsdl.port_types[port].operations))
    with client.settings(raw_response=True):
        response = client.service[first_operation](nfeDadosMsg=xml, _soapheaders=[xml_um])
        response, obj = sanitize_response(response.text)
        return {
            'sent_xml': xml_send,
            'received_xml': response,
            'object': obj.Body.nfeDistDFeInteresseResponse.nfeDistDFeInteresseResult
        }
开发者ID:danimaribeiro,项目名称:PyTrustNFe,代码行数:33,代码来源:__init__.py

示例2: _send

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
def _send(certificado, method, **kwargs):
    xml_send = kwargs["xml"]
    base_url = localizar_url(
        method,  kwargs['estado'], kwargs['modelo'], kwargs['ambiente'])

    cert, key = extract_cert_and_key_from_pfx(
        certificado.pfx, certificado.password)
    cert, key = save_cert_key(cert, key)

    session = Session()
    session.cert = (cert, key)
    session.verify = False
    transport = Transport(session=session)

    xml = etree.fromstring(xml_send)
    client = Client(base_url, transport=transport)

    port = next(iter(client.wsdl.port_types))
    first_operation = next(iter(client.wsdl.port_types[port].operations))
    
    namespaceNFe = xml.find(".//{http://www.portalfiscal.inf.br/nfe}NFe")
    if namespaceNFe is not None:
        namespaceNFe.set('xmlns', 'http://www.portalfiscal.inf.br/nfe')
            
    with client.settings(raw_response=True):
        response = client.service[first_operation](xml)
        response, obj = sanitize_response(response.text)
        return {
            'sent_xml': xml_send,
            'received_xml': response,
            'object': obj.Body.getchildren()[0]
        }
开发者ID:danimaribeiro,项目名称:PyTrustNFe,代码行数:34,代码来源:__init__.py

示例3: create_session

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
 def create_session(self, alias, headers=None, auth=None, verify="False", cert=None):
     session = Session()
     if headers:
         session.headers.update(headers)
     if auth:
         session.auth = tuple(auth)
     session.verify = self._builtin.convert_to_boolean(verify)
     session.cert = cert
     self._cache.register(session, alias)
开发者ID:rmerkushin,项目名称:RestLibrary,代码行数:11,代码来源:keywords.py

示例4: https

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
def https():
    uri = 'https://localhost:8443/' + os.environ.get('TEST_TARGET', '')
    s = Session()
    s.cert = (cert_path, key_path)
    s.headers.update({'user': 'testuser'})
    s.verify = cacert_path
    r = s.get(uri)
    print("TARGET:      {}".format(uri))
    print("STATUS_CODE: {}".format(r.status_code))
    print("TEXT:        {}".format(r.text))
开发者ID:kazufusa,项目名称:til,代码行数:12,代码来源:access-test.py

示例5: create_service_management

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
def create_service_management(service_class):
    if credentials.getUseRequestsLibrary():
        from requests import Session
        session = Session()
        session.cert = credentials.getManagementCertFile()
        service = service_class(credentials.getSubscriptionId(),
                            request_session=session)
    else:
        service = service_class(credentials.getSubscriptionId(),
                            credentials.getManagementCertFile())
    set_service_options(service)
    return service
开发者ID:feoff3,项目名称:azure-sdk-for-python,代码行数:14,代码来源:util.py

示例6: __init__

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
    def __init__(self, wsdl, cert=None, verify=True, timeout=8, **kwargs):
        session = Session()
        session.cert = cert
        session.verify = verify
        session.timeout = timeout
        session.headers.update({'Content-Type': 'text/xml;charset=UTF-8'})

        transport = Transport(
            operation_timeout=timeout,
            session=session
        )

        super().__init__(wsdl=wsdl, transport=transport, **kwargs)
开发者ID:solidarium,项目名称:correios,代码行数:15,代码来源:soap.py

示例7: create_rest_session

# 需要导入模块: from requests import Session [as 别名]
# 或者: from requests.Session import cert [as 别名]
    def create_rest_session(self, alias, headers=None, auth=None, verify=False, cert=None):
        """
        Creates REST session with specified alias.

        Arguments:
        | alias | session alias |
        | headers | custom headers for all requests |
        | auth | basic auth |
        | verify | SSL verification |
        | cert | path to SSL certificate file |

        Example usage:
        | ${headers} | Create Dictionary | Content-Type | application/json |
        | @{service_basic_auth} | Set Variable | username | password |
        | Create Rest Session | session_alias | headers=${headers} | auth=${service_basic_auth} | verify=False |
        """
        session = Session()
        if headers:
            session.headers.update(headers)
        if auth:
            session.auth = tuple(auth)
        session.verify = self._builtin.convert_to_boolean(verify)
        session.cert = cert
        self._cache.register(session, alias)
开发者ID:rmerkushin,项目名称:robotframework-http,代码行数:26,代码来源:rest.py


注:本文中的requests.Session.cert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。