Included connection reset handling in execute.py and extended it to handle both data and files in the inputs

This commit is contained in:
Lyncoln
2026-10-26 09:24:03 -04:00
parent e60be50447
commit bcca8f6ab2
+28 -12
View File
@@ -1,12 +1,17 @@
import requests
import threading
import os
from .request import buildRequest
#session = requests.Session()
_thread_local = threading.local()
def getSession():
#def getSession():
def getSession(reset=False):
if reset and hasattr(_thread_local, "session"):
_thread_local.session.close()
del _thread_local.session
if not hasattr(_thread_local, "session"):
session = requests.Session()
session.name = threading.current_thread().name
@@ -18,13 +23,33 @@ def getSession():
def executeRequest(action, outputs, resolved):
session = getSession()
session_log = bool(os.environ.get("LOGS_SESSION", False))
if session_log:
print(
f"Session {session.name} used by "
f"{threading.current_thread().name} thread"
)
try:
request, outputs = buildRequest(action, outputs, resolved)
response = session.request(
method=request["method"],
url=request["path"],
json=request.get("object"),
headers=request.get("headers"),
data=request.get("data"),
files=request.get("files")
)
except requests.ConnectionError as error:
print(f"Request failed due to {error} during {action.name}")
session = getSession(reset=True)
print(f"Retrying {action.name}")
response = session.request(
method=request["method"],
url=request["path"],
@@ -33,15 +58,6 @@ def executeRequest(action, outputs, resolved):
data=request.get("data")
)
# if definition hasattr(cookies):
# sessioncookies = {}
return response, outputs
# for cookie_name, cookie_key in cookies:
# session.cookies.set(
# sessioncookies[cookie_name] = response[cookie_key],
#print(request)
#print(response.status_code)
#print(response.text)
return response, outputs