本文整理汇总了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
}
示例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]
}
示例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)
示例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))
示例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
示例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)
示例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)