|
|
@ -1,4 +1,4 @@ |
|
|
#coding=utf-8 |
|
|
|
|
|
|
|
|
# coding=utf-8 |
|
|
''' |
|
|
''' |
|
|
Created on Jun 14, 2015 |
|
|
Created on Jun 14, 2015 |
|
|
|
|
|
|
|
|
@ -7,16 +7,13 @@ Created on Jun 14, 2015 |
|
|
|
|
|
|
|
|
from lxml import objectify |
|
|
from lxml import objectify |
|
|
from uuid import uuid4 |
|
|
from uuid import uuid4 |
|
|
import xml.etree.ElementTree as ET |
|
|
|
|
|
from xml.etree.ElementTree import tostring |
|
|
|
|
|
|
|
|
from pytrustnfe.xml.DynamicXml import DynamicXml |
|
|
from pytrustnfe.HttpClient import HttpClient |
|
|
from pytrustnfe.HttpClient import HttpClient |
|
|
from pytrustnfe.Certificado import converte_pfx_pem |
|
|
from pytrustnfe.Certificado import converte_pfx_pem |
|
|
|
|
|
|
|
|
from xml.dom.minidom import parseString |
|
|
from xml.dom.minidom import parseString |
|
|
|
|
|
|
|
|
from pytrustnfe.Strings import CONSULTA_CADASTRO_COMPLETA |
|
|
|
|
|
|
|
|
|
|
|
common_namespaces = { 'soap': 'http://www.w3.org/2003/05/soap-envelope' } |
|
|
|
|
|
|
|
|
common_namespaces = {'soap': 'http://www.w3.org/2003/05/soap-envelope'} |
|
|
|
|
|
|
|
|
soap_body_path = './soap:Envelope/soap:Body' |
|
|
soap_body_path = './soap:Envelope/soap:Body' |
|
|
soap_fault_path = './soap:Envelope/soap:Body/soap:Fault' |
|
|
soap_fault_path = './soap:Envelope/soap:Body/soap:Fault' |
|
|
@ -33,18 +30,18 @@ class Comunicacao(object): |
|
|
self.senha = senha |
|
|
self.senha = senha |
|
|
|
|
|
|
|
|
def _soap_xml(self, body): |
|
|
def _soap_xml(self, body): |
|
|
return '<?xml version="1.0" encoding="utf-8"?>'\ |
|
|
|
|
|
'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">'\ |
|
|
|
|
|
'<soap:Header>'\ |
|
|
|
|
|
'<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/' + self.metodo + '">'\ |
|
|
|
|
|
'<cUF>42</cUF><versaoDados>2.00</versaoDados>'\ |
|
|
|
|
|
'</nfeCabecMsg>'\ |
|
|
|
|
|
'</soap:Header>'\ |
|
|
|
|
|
'<soap:Body>'\ |
|
|
|
|
|
'<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/' + self.metodo + '">'\ |
|
|
|
|
|
+ body + '</nfeDadosMsg>'\ |
|
|
|
|
|
'</soap:Body>'\ |
|
|
|
|
|
'</soap:Envelope>' |
|
|
|
|
|
|
|
|
xml = '''<?xml version="1.0" encoding="utf-8"?> |
|
|
|
|
|
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> |
|
|
|
|
|
<soap:Header> |
|
|
|
|
|
<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/''' |
|
|
|
|
|
xml += self.metodo |
|
|
|
|
|
xml += '''"><cUF>42</cUF><versaoDados>2.00</versaoDados> |
|
|
|
|
|
</nfeCabecMsg> |
|
|
|
|
|
</soap:Header> |
|
|
|
|
|
<soap:Body> |
|
|
|
|
|
<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/''' |
|
|
|
|
|
xml += self.metodo + '">' + body |
|
|
|
|
|
xml += '</nfeDadosMsg></soap:Body></soap:Envelope>' |
|
|
|
|
|
|
|
|
def _preparar_temp_pem(self): |
|
|
def _preparar_temp_pem(self): |
|
|
chave_temp = '/tmp/' + uuid4().hex |
|
|
chave_temp = '/tmp/' + uuid4().hex |
|
|
@ -86,9 +83,8 @@ class Comunicacao(object): |
|
|
soap_xml = self._soap_xml(xmlEnviar) |
|
|
soap_xml = self._soap_xml(xmlEnviar) |
|
|
xml_retorno = client.post_xml(self.web_service, soap_xml) |
|
|
xml_retorno = client.post_xml(self.web_service, soap_xml) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dom = parseString(xml_retorno) |
|
|
dom = parseString(xml_retorno) |
|
|
nodes = dom.getElementsByTagNameNS(common_namespaces['soap'],'Fault') |
|
|
|
|
|
|
|
|
nodes = dom.getElementsByTagNameNS(common_namespaces['soap'], 'Fault') |
|
|
if len(nodes) > 0: |
|
|
if len(nodes) > 0: |
|
|
return nodes[0].toxml(), None |
|
|
return nodes[0].toxml(), None |
|
|
|
|
|
|
|
|
@ -98,7 +94,3 @@ class Comunicacao(object): |
|
|
return nodes[0].toxml(), obj |
|
|
return nodes[0].toxml(), obj |
|
|
|
|
|
|
|
|
return xml_retorno, objectify.fromstring(xml_retorno) |
|
|
return xml_retorno, objectify.fromstring(xml_retorno) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|