Se modificaron tareas asincronas

This commit is contained in:
2025-08-21 15:41:45 -06:00
parent 5f80629470
commit cc655f3d1c
3 changed files with 15 additions and 6 deletions

View File

@@ -60,7 +60,7 @@ class APIController:
""" """
Método para obtener las credenciales de VUCEM desde la API. Método para obtener las credenciales de VUCEM desde la API.
""" """
return await self._make_request_async('GET', f'vucem/vucem/?contribuyente={importador}') return await self._make_request_async('GET', f'vucem/vucem/?importador={importador}')
async def post_pedimento_service(self, data: Dict[str, Any]) -> Dict[str, Any]: async def post_pedimento_service(self, data: Dict[str, Any]) -> Dict[str, Any]:
""" """
@@ -83,7 +83,7 @@ class APIController:
""" """
return await self._make_request_async('PUT', f'customs/pedimentos/{pedimento_id}/', data=data) return await self._make_request_async('PUT', f'customs/pedimentos/{pedimento_id}/', data=data)
async def post_document(self, soap_response=None, organizacion: str = None, pedimento: str = None, file_name: str = None, document_type: int = 2, binary_content: bytes = None) -> Dict[str, Any]: async def post_document(self, soap_response=None, organizacion: str = None, pedimento: str = None, file_name: str = None, document_type: int = 2, binary_content: bytes = None, fuente: int = 2) -> Dict[str, Any]:
""" """
Método para enviar documentos (XML, PDF, etc.) a la API. Método para enviar documentos (XML, PDF, etc.) a la API.
@@ -170,7 +170,8 @@ class APIController:
'pedimento': pedimento, 'pedimento': pedimento,
'extension': file_extension, 'extension': file_extension,
'document_type': document_type, 'document_type': document_type,
'size': file_size 'size': file_size,
'fuente': fuente
} }
# Subir archivo # Subir archivo

View File

@@ -14,11 +14,18 @@ class SOAPController:
self.base_url = settings.SOAP_SERVICE_URL self.base_url = settings.SOAP_SERVICE_URL
self.timeout = settings.TIMEOUT # Timeout por default self.timeout = settings.TIMEOUT # Timeout por default
import ssl
# Contexto SSL personalizado para permitir claves DH pequeñas
ssl_context = ssl.create_default_context()
ssl_context.set_ciphers('DEFAULT@SECLEVEL=1')
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
async def make_request(self, endpoint, data=None, headers=None, max_retries=5): async def make_request(self, endpoint, data=None, headers=None, max_retries=5):
intento = 0 intento = 0
while intento < settings.MAX_RETRIES: while intento < settings.MAX_RETRIES:
try: try:
with httpx.Client(verify=settings.context, timeout=self.timeout) as client: with httpx.Client(verify=self.ssl_context, timeout=self.timeout) as client:
content = data.encode('utf-8') if data else None content = data.encode('utf-8') if data else None
response = client.post( response = client.post(
f"{self.base_url}/{endpoint}", f"{self.base_url}/{endpoint}",
@@ -53,7 +60,7 @@ class SOAPController:
intento = 0 intento = 0
while intento < settings.MAX_RETRIES: while intento < settings.MAX_RETRIES:
try: try:
async with httpx.AsyncClient(verify=settings.context, timeout=self.timeout) as client: async with httpx.AsyncClient(verify=self.ssl_context, timeout=self.timeout) as client:
content = data.encode('utf-8') if data else None content = data.encode('utf-8') if data else None
response = await client.post( response = await client.post(
f"{self.base_url}/{endpoint}", f"{self.base_url}/{endpoint}",

View File

@@ -309,7 +309,8 @@ async def get_soap_pedimento_completo(credenciales, response_service, soap_contr
organizacion=response_service['organizacion'], organizacion=response_service['organizacion'],
pedimento=response_service['pedimento']['id'], pedimento=response_service['pedimento']['id'],
file_name=_file_name, file_name=_file_name,
document_type=2 document_type=2,
) )
data['organizacion'] = response_service['organizacion'] data['organizacion'] = response_service['organizacion']