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