From f0b5fa5ae9e1f18d998dc21e42eff2ddb50a90ca Mon Sep 17 00:00:00 2001 From: Mauricio Baeza Date: Tue, 9 Feb 2021 23:01:08 -0600 Subject: [PATCH] Fix - issue #422 --- source/app/controllers/utils.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/source/app/controllers/utils.py b/source/app/controllers/utils.py index d1c0ee2..32b9f9e 100644 --- a/source/app/controllers/utils.py +++ b/source/app/controllers/utils.py @@ -32,7 +32,7 @@ import subprocess import threading import zipfile from pathlib import Path -from urllib import request +from xml.sax.saxutils import escape from email.mime.multipart import MIMEMultipart from email.mime.base import MIMEBase @@ -705,20 +705,20 @@ def _get_data_sat(xml): BF = 'string(//*[local-name()="{}"]/@{})' NS_CFDI = {'cfdi': 'http://www.sat.gob.mx/cfd/3'} - try: - tree = etree.fromstring(xml.encode()) - emisor = escape( - tree.xpath('string(//cfdi:Emisor/@rfc)', namespaces=NS_CFDI) or - tree.xpath('string(//cfdi:Emisor/@Rfc)', namespaces=NS_CFDI) - ) - receptor = escape( - tree.xpath('string(//cfdi:Receptor/@rfc)', namespaces=NS_CFDI) or - tree.xpath('string(//cfdi:Receptor/@Rfc)', namespaces=NS_CFDI) - ) - total = tree.get('total') or tree.get('Total') - uuid = tree.xpath(BF.format('TimbreFiscalDigital', 'UUID')) - except Exception as e: - return '' + # ~ try: + tree = ET.fromstring(xml.encode()) + emisor = escape( + tree.xpath('string(//cfdi:Emisor/@rfc)', namespaces=NS_CFDI) or + tree.xpath('string(//cfdi:Emisor/@Rfc)', namespaces=NS_CFDI) + ) + receptor = escape( + tree.xpath('string(//cfdi:Receptor/@rfc)', namespaces=NS_CFDI) or + tree.xpath('string(//cfdi:Receptor/@Rfc)', namespaces=NS_CFDI) + ) + total = tree.get('total') or tree.get('Total') + uuid = tree.xpath(BF.format('TimbreFiscalDigital', 'UUID')) + # ~ except Exception as e: + # ~ return '' data = f'?re={emisor}&rr={receptor}&tt={total}&id={uuid}' return data @@ -751,7 +751,7 @@ def get_status_sat(xml): try: result = requests.post(URL, data=data, headers=headers) - tree = etree.fromstring(result.text) + tree = ET.fromstring(result.text) node = tree.xpath("//*[local-name() = 'Estado']")[0] except Exception as e: return 'Error: {}'.format(str(e))