From 6a563c833e10a89de2fb991329496bec062585d1 Mon Sep 17 00:00:00 2001 From: Junior Tada Date: Fri, 7 Aug 2015 11:46:33 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20bug=20resposta=20envio=20c?= =?UTF-8?q?om=20erro.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pynfe/processamento/comunicacao.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pynfe/processamento/comunicacao.py b/pynfe/processamento/comunicacao.py index 20bdb78..5e2e878 100644 --- a/pynfe/processamento/comunicacao.py +++ b/pynfe/processamento/comunicacao.py @@ -50,8 +50,14 @@ class ComunicacaoSefaz(Comunicacao): # Procuta status no xml ns = {'ns':'http://www.portalfiscal.inf.br/nfe'} # namespace prot = etree.fromstring(retorno.text) - prot = prot[1][0][0][6] # root protNFe - status = prot.xpath("ns:infProt/ns:cStat", namespaces=ns)[0].text + try: + # Protocolo com envio OK + infProt = prot[1][0][0][6] # root protNFe + status = infProt.xpath("ns:infProt/ns:cStat", namespaces=ns)[0].text + except IndexError: + # Protocolo com algum erro no Envio + retEnvi = prot[1][0][0] # root retEnvi + status = retEnvi.xpath("ns:cStat", namespaces=ns)[0].text if status == '100': raiz = etree.Element('nfeProc', xmlns=NAMESPACE_NFE, versao=VERSAO_PADRAO) raiz.append(nota_fiscal)