Hey @chkoss,
Thanks for the quick reply.Appreciate it a lot.
I have written the following statement in the actions run method.
api_response = await call_async_api(api_url)
The above statement is giving me a syntax error.I think the run methods in action classes are not async and when I define them as async, then the action is not running, as it is returning a coroutine and error says coroutine cannot be iterable.I am using rasa 1.3.X.Please let me know if its a version issue.
So, Instead I have made the changes you said regarding requests module to aiohttp and the code now is as below.
Changed my call_async_api function as below.
async def call_async_api(api_url):
timeout = aiohttp.ClientTimeout(total=20)
auth = aiohttp.BasicAuth("Username",'Password')
api_session = requests.Session()
async with aiohttp.ClientSession(auth=auth, timeout=timeout) as session:
async with session.get(api_url) as resp:
return resp.status, await resp.json()
My call_api is unchanged.
@start_event_loop
async def call_api(*args,**kwargs):
return await call_async_api(*args,**kwargs)
My start_event_loop function is:
def start_event_loop(func):
def inner(*args,**kwargs):
loop = asyncio.get_event_loop()
status,response = loop.run_until_complete(func(*args,**kwargs))
return status,response
return inner
And finally, in the action file, I am calling the call_api as follows
status, response = call_api(api_url)
With above code, still the issue persists.User B needs to wait until User A’s action api response returns.
I doubt the implementation of event loop and aiohttp Client session is correct. I am not sure what to do here.
Please let me know If I am doing anything incorrect.
Thanks in advance for the help.