From 825e23e369a8d587a003eb16387fe67d6d5a24ef Mon Sep 17 00:00:00 2001 From: El Mau Date: Mon, 24 Jan 2022 12:15:27 -0600 Subject: [PATCH] Mostrar el request enviado --- .../pacs/comerciodigital/comercio.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source/app/controllers/pacs/comerciodigital/comercio.py b/source/app/controllers/pacs/comerciodigital/comercio.py index b053c2e..d2bdf42 100644 --- a/source/app/controllers/pacs/comerciodigital/comercio.py +++ b/source/app/controllers/pacs/comerciodigital/comercio.py @@ -42,6 +42,23 @@ logging.getLogger('requests').setLevel(logging.ERROR) TIMEOUT = 10 +def pretty_print_POST(req): + """ + At this point it is completely built and ready + to be fired; it is "prepared". + + However pay attention at the formatting used in + this function because it is programmed to be pretty + printed and may differ from the actual request. + """ + print('{}\n{}\r\n{}\r\n\r\n{}'.format( + '-----------START-----------', + req.method + ' ' + req.url, + '\r\n'.join('{}: {}'.format(k, v) for k, v in req.headers.items()), + req.body, + )) + + class PACComercioDigital(object): ws = 'https://{}.comercio-digital.mx/{}' api = 'https://app2.comercio-digital.mx/{}' @@ -91,6 +108,7 @@ class PACComercioDigital(object): headers['host'] = url.split('/')[2] headers['Content-type'] = 'text/plain' headers['Connection'] = 'Keep-Alive' + headers['Expect'] = '100-continue' try: result = requests.post(url, data=data, headers=headers, timeout=TIMEOUT) @@ -251,6 +269,11 @@ class PACComercioDigital(object): url = self.URL['cancelxml'] headers = self._get_headers_cancel_xml(cfdi, info, auth) + + req = requests.Request('POST', url, headers=headers, data=xml) + prepared = req.prepare() + pretty_print_POST(prepared) + result = self._post(url, xml, headers) if result is None: