Included connection reset handling in execute.py and extended it to handle both data and files in the inputs
This commit is contained in:
+38
-22
@@ -1,12 +1,17 @@
|
|||||||
import requests
|
import requests
|
||||||
import threading
|
import threading
|
||||||
|
import os
|
||||||
from .request import buildRequest
|
from .request import buildRequest
|
||||||
|
|
||||||
#session = requests.Session()
|
#session = requests.Session()
|
||||||
_thread_local = threading.local()
|
_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"):
|
if not hasattr(_thread_local, "session"):
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
session.name = threading.current_thread().name
|
session.name = threading.current_thread().name
|
||||||
@@ -18,30 +23,41 @@ def getSession():
|
|||||||
def executeRequest(action, outputs, resolved):
|
def executeRequest(action, outputs, resolved):
|
||||||
session = getSession()
|
session = getSession()
|
||||||
|
|
||||||
print(
|
session_log = bool(os.environ.get("LOGS_SESSION", False))
|
||||||
f"Session {session.name} used by "
|
|
||||||
f"{threading.current_thread().name} thread"
|
|
||||||
)
|
|
||||||
|
|
||||||
request, outputs = buildRequest(action, outputs, resolved)
|
if session_log:
|
||||||
|
print(
|
||||||
response = session.request(
|
f"Session {session.name} used by "
|
||||||
method=request["method"],
|
f"{threading.current_thread().name} thread"
|
||||||
url=request["path"],
|
|
||||||
json=request.get("object"),
|
|
||||||
headers=request.get("headers"),
|
|
||||||
data=request.get("data")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# if definition hasattr(cookies):
|
try:
|
||||||
# sessioncookies = {}
|
request, outputs = buildRequest(action, outputs, resolved)
|
||||||
|
|
||||||
# for cookie_name, cookie_key in cookies:
|
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")
|
||||||
|
)
|
||||||
|
|
||||||
# session.cookies.set(
|
except requests.ConnectionError as error:
|
||||||
# sessioncookies[cookie_name] = response[cookie_key],
|
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"],
|
||||||
|
json=request.get("object"),
|
||||||
|
headers=request.get("headers"),
|
||||||
|
data=request.get("data")
|
||||||
|
)
|
||||||
|
|
||||||
|
return response, outputs
|
||||||
|
|
||||||
#print(request)
|
|
||||||
#print(response.status_code)
|
|
||||||
#print(response.text)
|
|
||||||
return response, outputs
|
return response, outputs
|
||||||
|
|||||||
Reference in New Issue
Block a user