48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
import requests
|
|
import threading
|
|
|
|
from .request import buildRequest
|
|
|
|
#session = requests.Session()
|
|
_thread_local = threading.local()
|
|
|
|
def getSession():
|
|
if not hasattr(_thread_local, "session"):
|
|
session = requests.Session()
|
|
session.name = threading.current_thread().name
|
|
_thread_local.session = session
|
|
|
|
return _thread_local.session
|
|
|
|
|
|
def executeRequest(action, outputs, resolved):
|
|
session = getSession()
|
|
|
|
print(
|
|
f"Session {session.name} used by "
|
|
f"{threading.current_thread().name} thread"
|
|
)
|
|
|
|
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")
|
|
)
|
|
|
|
# if definition hasattr(cookies):
|
|
# sessioncookies = {}
|
|
|
|
# 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
|