Ejemplo n.º 1
0
def _send(certificado, method, **kwargs):
    url = _get_url(**kwargs)

    path = os.path.join(os.path.dirname(__file__), 'templates')

    xml_send = _render(path, method, **kwargs)
    client = get_client(url)
    response = False

    if certificado:
        cert, key = extract_cert_and_key_from_pfx(certificado.pfx,
                                                  certificado.password)
        cert, key = save_cert_key(cert, key)
        signer = Assinatura(cert, key, certificado.password)
        xml_send = signer.assina_xml(xml_send, '')

    try:
        response = getattr(client.service, method)(xml_send)
        response, obj = sanitize_response(response.encode())
    except suds.WebFault as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
            'object': None
        }
    except Exception as e:
        if response:
            raise Exception(response)
        else:
            raise e

    return {'sent_xml': xml_send, 'received_xml': response, 'object': obj}
Ejemplo n.º 2
0
def _send(method, **kwargs):
    if kwargs['ambiente'] == 'producao':
        base_url = 'http://www.susesu.com.br/wsnfd/serviconfd.asmx?WSDL'
    else:
        base_url = 'http://pira.comunix.net:5002/gestaopublica/wsnfd/ServicoNfd.asmx?WSDL'  # noqa

    client = get_client(base_url)
    try:
        xml_send = kwargs["xml"]
        result = getattr(client.service, method)(__inject={'msg': xml_send})
    except Exception as e:
        return {
            'sent_xml': xml_send,
            'received_xml': e.fault.faultstring,
        }
    result = str(result)
    result = unicodedata.normalize('NFKD', result).encode('ascii', 'ignore')
    return {
        'sent_xml': xml_send,
        'received_xml': result,
    }
Ejemplo n.º 3
0
def _send(method, **kwargs):
    if kwargs["ambiente"] == "producao":
        base_url = "http://www.susesu.com.br/wsnfd/serviconfd.asmx?WSDL"
    else:
        base_url = "http://pira.comunix.net:5002/gestaopublica/wsnfd/ServicoNfd.asmx?WSDL"  # noqa

    client = get_client(base_url)
    try:
        xml_send = kwargs["xml"]
        result = getattr(client.service, method)(__inject={"msg": xml_send})
    except Exception as e:
        return {
            "sent_xml": xml_send,
            "received_xml": e.fault.faultstring,
        }
    result = str(result)
    result = unicodedata.normalize("NFKD", result).encode("ascii", "ignore")
    return {
        "sent_xml": xml_send,
        "received_xml": result,
    }