Browse Source

Normalize xml antes de assinatura.

pull/1/head
Junior Tada 10 years ago
parent
commit
668d1c3e92
  1. 5
      pynfe/processamento/assinatura.py
  2. 3
      pynfe/processamento/comunicacao.py
  3. 2
      pynfe/processamento/serializacao.py

5
pynfe/processamento/assinatura.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from pynfe.utils import etree
from pynfe.utils import etree, remover_acentos
import subprocess
@ -47,8 +47,9 @@ class AssinaturaA1(Assinatura):
xml.append(raiz)
# Escreve no arquivo depois de remover caracteres especiais e parse string
with open('testes.xml', 'w') as arquivo:
arquivo.write(etree.tostring(xml, encoding="unicode", pretty_print=False))
arquivo.write(remover_acentos(etree.tostring(xml, encoding="unicode", pretty_print=False)))
subprocess.call(['xmlsec1', '--sign', '--pkcs12', self.certificado, '--pwd', self.senha, '--crypto', 'openssl', '--output', 'funfa.xml', '--id-attr:Id', tag, 'testes.xml'])
xml = etree.parse('funfa.xml').getroot()

3
pynfe/processamento/comunicacao.py

@ -2,7 +2,7 @@
import datetime
import time
import requests
from pynfe.utils import etree, so_numeros, remover_acentos
from pynfe.utils import etree, so_numeros
from pynfe.utils.flags import NAMESPACE_NFE, NAMESPACE_SOAP, NAMESPACE_XSI, NAMESPACE_XSD, NAMESPACE_METODO, VERSAO_PADRAO, CODIGOS_ESTADOS
from pynfe.utils.webservices import NFCE, NFE
from .assinatura import AssinaturaA1
@ -287,7 +287,6 @@ class ComunicacaoSefaz(Comunicacao):
xml_declaration='<?xml version="1.0" encoding="utf-8"?>'
xml = etree.tostring(xml, encoding='unicode', pretty_print=False).replace('\n','')
xml = xml_declaration + xml
xml = remover_acentos(xml)
# Faz o request com o servidor
result = requests.post(url, xml, headers=self._post_header(), cert=chave_cert, verify=False)
result.encoding='utf-8'

2
pynfe/processamento/serializacao.py

@ -143,6 +143,8 @@ class SerializacaoXML(Serializacao):
# Inscrição Municipal do tomador do serviço
if cliente.inscricao_municipal:
etree.SubElement(raiz, 'IM').text = cliente.inscricao_municipal
# E-mail
if cliente.email:
etree.SubElement(raiz, 'email').text = cliente.email
if retorna_string:
return etree.tostring(raiz, encoding="unicode", pretty_print=True)

Loading…
Cancel
Save