Cambios en el SAT

This commit is contained in:
El Mau 2022-03-27 22:15:42 -06:00
parent 0be7f898c1
commit 36d2ce887b
1 changed files with 26 additions and 8 deletions

View File

@ -8,6 +8,8 @@ from datetime import datetime, timedelta
import httpx
import lxml.etree as ET
from conf import TIMEOUT
class SATWebService():
BASE = 'https://cfdidescargamasivasolicitud.clouda.sat.gob.mx'
@ -170,6 +172,7 @@ class SATWebService():
node_name = f"{{{self.NS['s']}}}Header"
header = ET.SubElement(root, node_name)
node_name = 'ActivityId'
attr = {'CorrelationId': '806aad0d-ef46-443b-9741-040c8e8e8c7d'}
nsmap = {None: 'http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics'}
@ -197,17 +200,20 @@ class SATWebService():
attr = {
'FechaInicial': date_start.strftime(FORMAT),
'FechaFinal': date_end.strftime(FORMAT),
args['rfc']: self._cert.rfc,
'RfcSolicitante': self._cert.rfc,
'TipoSolicitud': type_request,
'RfcACuentaTerceros': '',
# ~ 'RfcACuentaTerceros': '',
}
if args['rfc'] == 'RfcEmisor':
attr['RfcEmisor'] = self._cert.rfc
request = ET.SubElement(request_down, node_name, attr)
node_name = 'RfcReceptores'
node_receptores = ET.SubElement(request, node_name)
node_name = 'RfcReceptor'
ET.SubElement(node_receptores, node_name)
node_receptor = ET.SubElement(node_receptores, node_name)
if args['rfc'] == 'RfcReceptor':
node_receptor.text = self._cert.rfc
nsmap = {None: self.NS['xd']}
signature = ET.SubElement(request, 'Signature', nsmap=nsmap)
@ -250,9 +256,9 @@ class SATWebService():
x_serial_number.text = str(self._cert.serial_number2)
x_cert.text = self._cert.cer_txt
# ~ soap = ET.tostring(root, pretty_print=True, encoding='utf-8')
soap = ET.tostring(root)
# ~ soap = b'<?xml version="1.0"?>\n' + ET.tostring(root, pretty_print=True, encoding='utf-8')
soap = ET.tostring(root, pretty_print=True)
# ~ print(soap.decode())
return soap
def request_download(self, args):
@ -262,7 +268,13 @@ class SATWebService():
headers['Authorization'] = f'WRAP access_token="{self._token}"'
data = self._get_data_req(args)
response = httpx.post(self.URL['REQ'], data=data, headers=headers)
try:
response = httpx.post(self.URL['REQ'],
data=data, headers=headers, timeout=TIMEOUT)
except httpx.TimeoutException as exc:
print(exc)
return
if response.status_code != httpx.codes.OK:
self._error = f'Status: {response.status_code} - {response.text}'
return
@ -435,7 +447,13 @@ class SATWebService():
headers['Authorization'] = f'WRAP access_token="{self._token}"'
data = self._get_data_download(args)
response = httpx.post(self.URL['DOWN'], data=data, headers=headers)
try:
response = httpx.post(self.URL['DOWN'],
data=data, headers=headers, timeout=TIMEOUT)
except httpx.TimeoutException as exc:
print(exc)
return
if response.status_code != httpx.codes.OK:
self._error = f'Status: {response.status_code} - {response.text}'
return