From fe684c2aedc015d3f105b7e1112a45f36f2aecaf Mon Sep 17 00:00:00 2001 From: Junior Tada Date: Wed, 29 Jul 2015 18:10:16 -0300 Subject: [PATCH] teste assinando com xmlsec1 --- pynfe/processamento/assinatura.py | 3 ++- pynfe/processamento/comunicacao.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pynfe/processamento/assinatura.py b/pynfe/processamento/assinatura.py index d75ddde..216aac7 100644 --- a/pynfe/processamento/assinatura.py +++ b/pynfe/processamento/assinatura.py @@ -49,7 +49,8 @@ class AssinaturaA1(Assinatura): with open('testes.xml', 'w') as arquivo: arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False)) - subprocess.check_call('xmlsec1 --sign --pkcs12 '+self.certificado+' --pwd '+self.senha+' --crypto openssl --output funciona.xml --id-attr:Id infNFe testes.xml') + subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', 'infNFe', 'testes.xml']) + xml = etree.parse('funfa.xml').getroot() if retorna_string: return etree.tostring(xml, encoding="unicode", pretty_print=False) diff --git a/pynfe/processamento/comunicacao.py b/pynfe/processamento/comunicacao.py index 06cf249..1a1d21f 100644 --- a/pynfe/processamento/comunicacao.py +++ b/pynfe/processamento/comunicacao.py @@ -35,9 +35,9 @@ class ComunicacaoSefaz(Comunicacao): url = self._get_url(modelo=modelo, consulta='AUTORIZACAO') # Monta XML do corpo da requisição raiz = etree.Element('enviNFe', versao=VERSAO_PADRAO, xmlns=NAMESPACE_NFE) - #etree.SubElement(raiz, 'versao').text = self._versao + etree.SubElement(raiz, 'versao').text = self._versao etree.SubElement(raiz, 'idLote').text = str(1) # numero autoincremental gerado pelo sistema - etree.SubElement(raiz, 'indSinc').text = str(1) # 0 para assincrono, 1 para sincrono + etree.SubElement(raiz, 'indSinc').text = str(0) # 0 para assincrono, 1 para sincrono #etree.SubElement(raiz, 'NFe').text = nota_fiscal # conjunto de nfe tramistidas (max 50) raiz.append(nota_fiscal) # Monta XML para envio da requisição @@ -189,8 +189,8 @@ class ComunicacaoSefaz(Comunicacao): u"""Monta o XML do cabeçalho da requisição SOAP""" raiz = etree.Element('nfeCabecMsg', xmlns=NAMESPACE_METODO+metodo) - etree.SubElement(raiz, 'cUF').text = CODIGOS_ESTADOS[self.uf.upper()] etree.SubElement(raiz, 'versaoDados').text = VERSAO_PADRAO + etree.SubElement(raiz, 'cUF').text = CODIGOS_ESTADOS[self.uf.upper()] return raiz def _construir_xml_soap(self, cabecalho, metodo, dados): @@ -228,10 +228,10 @@ class ComunicacaoSefaz(Comunicacao): try: xml_declaration='' # Passa o lxml.etree para string - xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('ds:','').replace(':ds','') + xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('\n','') xml = xml_declaration + xml + #print (xml) # Faz o request com o servidor - print (xml) result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False) if result == 200: result.encoding='utf-8'