diff --git a/pytrustnfe/servicos/Comunicacao.py b/pytrustnfe/servicos/Comunicacao.py index 91387c6..4db7fdb 100644 --- a/pytrustnfe/servicos/Comunicacao.py +++ b/pytrustnfe/servicos/Comunicacao.py @@ -12,8 +12,16 @@ from xml.etree.ElementTree import tostring from pytrustnfe.HttpClient import HttpClient from pytrustnfe.Certificado import converte_pfx_pem +from xml.dom.minidom import parseString + from pytrustnfe.Strings import CONSULTA_CADASTRO_COMPLETA +common_namespaces = { 'soap': 'http://www.w3.org/2003/05/soap-envelope' } + +soap_body_path = './soap:Envelope/soap:Body' +soap_fault_path = './soap:Envelope/soap:Body/soap:Fault' + + class Comunicacao(object): url = '' web_service = '' @@ -28,12 +36,12 @@ class Comunicacao(object): return ''\ ''\ ''\ - ''\ + ''\ '422.00'\ ''\ ''\ ''\ - ''\ + ''\ + body + ''\ ''\ '' @@ -68,11 +76,19 @@ class Comunicacao(object): client = HttpClient(self.url, chave, certificado) soap_xml = self._soap_xml(xmlEnviar) xml_retorno = client.post_xml(self.web_service, soap_xml) - - tree = ET.fromstring(xml_retorno) - node = tree.find(self.tag_retorno) - node = tostring(node) - obj = objectify.fromstring(node) - return xml_retorno, obj + + + dom = parseString(xml_retorno) + nodes = dom.getElementsByTagNameNS(common_namespaces['soap'],'Fault') + if len(nodes) > 0: + return nodes[0].toxml(), None + + nodes = dom.getElementsByTagName(self.tag_retorno) + if len(nodes) > 0: + obj = objectify.fromstring(nodes[0].toxml()) + return nodes[0].toxml(), obj + + + \ No newline at end of file diff --git a/pytrustnfe/servicos/NfeConsultaCadastro.py b/pytrustnfe/servicos/NfeConsultaCadastro.py index 105855a..7b494c6 100644 --- a/pytrustnfe/servicos/NfeConsultaCadastro.py +++ b/pytrustnfe/servicos/NfeConsultaCadastro.py @@ -13,7 +13,7 @@ class NfeConsultaCadastro(Comunicacao): def __init__(self, certificado, senha): super(NfeConsultaCadastro, self).__init__(certificado, senha) self.metodo = 'CadConsultaCadastro2' - self.tag_retorno = 'consultaCadastro2Result' + self.tag_retorno = 'retConsCad' def consultar_cadastro(self, cadastro, estado):