Mostrar el request enviado

This commit is contained in:
El Mau 2022-01-24 12:15:27 -06:00
parent 121831a139
commit 825e23e369
1 changed files with 23 additions and 0 deletions

View File

@ -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: