From fc7dc1d690d5af94a005e76a9a8ac40039efaa07 Mon Sep 17 00:00:00 2001 From: Victor Pereira Date: Thu, 24 May 2018 21:47:27 -0300 Subject: [PATCH] #33 1. Fix convert response sefaz in XML 2. Fix get nRec in XML Closed #33 --- pynfe/processamento/comunicacao.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pynfe/processamento/comunicacao.py b/pynfe/processamento/comunicacao.py index 36e061b..fbeb511 100644 --- a/pynfe/processamento/comunicacao.py +++ b/pynfe/processamento/comunicacao.py @@ -102,12 +102,16 @@ class ComunicacaoSefaz(Comunicacao): print(retorno.text) else: # Retorna id do protocolo para posterior consulta em caso de sucesso. - rec = etree.fromstring(retorno.text) + try: + rec = etree.fromstring(retorno.text) + except ValueError: + # em SP retorno.text apresenta erro + rec = etree.fromstring(retorno.content) rec = rec[0][0] status = rec.xpath("ns:retEnviNFe/ns:cStat", namespaces=ns)[0].text # Lote Recebido com Sucesso! if status == '103': - nrec = rec.xpath("ns:infRec/ns:nRec", namespaces=ns)[0].text + nrec = rec.xpath("ns:retEnviNFe/ns:infRec/ns:nRec", namespaces=ns)[0].text return 0, nrec, nota_fiscal return 1, retorno, nota_fiscal