Skip to content

Commit f38d241

Browse files
Opción para especificar timeouts en las peticiones al webservice del SAT, 15 segs por defecto
1 parent b4dfa8d commit f38d241

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

cfdiclient/validacioncfdi.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55

66
class Validacion():
7-
def __init__(self):
7+
def __init__(self, verify=True, timeout=15):
88
self.SOAP_URL = 'https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc'
99
self.SOAP_ACTION = 'http://tempuri.org/IConsultaCFDIService/Consulta'
1010
self.NSMAP = {
1111
's': 'http://schemas.xmlsoap.org/soap/envelope/',
1212
'des': 'http://DescargaMasivaTerceros.sat.gob.mx',
1313
'xd': 'http://www.w3.org/2000/09/xmldsig#'
1414
}
15+
self.verify = verify
16+
self.timeout = timeout
1517

1618
def __generar_soapreq__(self, rfc_emisor, rfc_receptor, total, uuid):
1719
soapreq = ('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">'
@@ -38,7 +40,13 @@ def obtener_estado(self, rfc_emisor, rfc_receptor, total, uuid):
3840
'SOAPAction': self.SOAP_ACTION,
3941
}
4042

41-
response = requests.post(self.SOAP_URL, data=soapreq, headers=headers, verify=True)
43+
response = requests.post(
44+
self.SOAP_URL,
45+
data=soapreq,
46+
headers=headers,
47+
verify=self.verify,
48+
timeout=self.timeout,
49+
)
4250

4351

4452
if response.status_code != requests.codes['ok']:

cfdiclient/webservicerequest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class WebServiceRequest(Utils):
2323

2424
fault_xpath: str = 's:Body/s:Fault/faultstring'
2525

26-
def __init__(self, fiel: Fiel, verify: bool = True) -> None:
26+
def __init__(self, fiel: Fiel, verify: bool = True, timeout: int = 15) -> None:
2727
super().__init__()
2828
self.signer = Signer(fiel)
2929
self.verify = verify
30+
self.timeout = timeout
3031

3132
def get_headers(self, token: str) -> dict:
3233
headers = {
@@ -74,6 +75,7 @@ def request(self, token: str = None, arguments: dict = None) -> etree.Element:
7475
data=soap_request,
7576
headers=headers,
7677
verify=self.verify,
78+
timeout=self.timeout,
7779
)
7880

7981
logger.debug('Response headers: %s', response.headers)

0 commit comments

Comments
 (0)