asyncio.TimeoutError

I am trying to fetch a value from a database through an API. I am able to do so successfully and print those in the terminal through actions.py, but the bot is not able to show those values and it raises an error asyncio.TimeoutError Traceback (most recent call last): File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/rasa/core/run.py”, line 134, in run_cmdline_io sender_id=conversation_id, File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/rasa/core/channels/console.py”, line 139, in record_messages async for response in bot_responses: File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/rasa/core/channels/console.py”, line 105, in send_message_receive_stream async for line in resp.content: File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/aiohttp/streams.py”, line 39, in anext rv = await self.read_func() File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/aiohttp/streams.py”, line 328, in readline await self._wait(‘readline’) File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/aiohttp/streams.py”, line 296, in _wait await waiter File “/Users/gandharv/opt/anaconda3/lib/python3.7/site-packages/aiohttp/helpers.py”, line 596, in exit raise asyncio.TimeoutError from None concurrent.futures._base.TimeoutError Transport closed @ (‘127.0.0.1’, 60445) and exception experienced during error handling

Here is my actions.py file

from typing import Any, Text, Dict, List from rasa_sdk import Action, Tracker from rasa_sdk.executor import CollectingDispatcher from email.message import EmailMessage from rasa_core_sdk.events import SlotSet import smtplib import psycopg2

class ActionHelloWorld(Action):

def name(self) -> Text:
    return "action_hello_world"

def run(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:

Getting slot values

    sender_email = tracker.get_slot('email')
    entity_name = tracker.get_slot('entity_name')

DatabaseConncetion

    user = "my user"
    password = "mypass"
    host = " "
    port = 8081
    database = "dla"
    
    db_conn = psycopg2.connect(host=host, user=user, password=password, database=database)
    cursor = db_conn.cursor()
    sql_query = "SELECT * FROM operational_metadata WHERE bor_name = %s; "
    cursor.execute(sql_query, (entity_name,))
    result = cursor.fetchall()
    for row in result:
        a0 = row[0]
        a1 = row[1]
        a2 = row[2]
        a3 = row[3]
        a4 = row[4]
        a5 = row[5]
        a6 = row[6]
        a7 = row[7]
        a8 = row[8]
        a9 = row[9]
        a10 = row[10]
        a11 = row[11]
        a12 = row[12]
        a13 = row[13]
        a14 = row[14]
        a15 = row[15]
        a16 = row[16]
    response = """ details are: {}, {}, {}, {}, {},  {},  {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}.""".format(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16)
    print(response)
    dispatcher.utter_message(response)

SendingEmail

    msg = EmailMessage()
    msg.set_content(response)
    msg['Subject'] = 'Final Testing'
    msg['From'] = "myemail"
    msg['To'] = sender_email
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.login("myemail", "mypass")
    server.send_message(msg)
    server.quit()
    return [SlotSet('email',sender_email),SlotSet('entity_name',entity_name)]

I am using Rasa 1.9.5 and rasa shell command along with rasa run actions to run the action server

1 Like

Hey @gandharv30 that happens refer this Multiple sequential actions cause asyncio TimeoutError · Issue #4381 · RasaHQ/rasa · GitHub and when I’m integrating with it telegram, giving me all responses with out any asyncio error

2 Likes

Thanks @bparikh99, I did refer to this. But it did not help me much. My code does not takes 10 sec to execute as I its evident from terminal. Could you help me solve this issue? Also @Juste

@gandharv30 updating rasa could solve your proble, i think so!!

I am using the latest version @bparikh99

hi dear i was face alot of these errors now lets debug where is the error. first before the

db_conn

type try:

and after

dispatcher.utter_message(response)

type

except mysql.connector.Error as error:

        print("parameterized query failed {}".format(error))

        dispatcher.utter_message("error messages here")

just make the right format for the code then in the terminal you will get the error where exactly.

2nd method to trace it in each line by line type some deferent print to terminal to see witch of these is work and where the error occurs .

hope that help you.

I am facing the same issue, did you solve it?

@andrejankas What is your current issue or error, can you even share the rasa --version and error screenshot?

Versions

Rasa Version      :         2.8.7
Minimum Compatible Version: 2.8.0
Rasa SDK Version  :         2.8.1
Rasa X Version    :         None
Python Version    :         3.7.9
Operating System  :         Windows-10-10.0.19041-SP0

Error

2021-09-29 10:33:59 ERROR    asyncio  - Task exception was never retrieved
future: <Task finished coro=<configure_app.<locals>.run_cmdline_io() done, defined at c:\users\anka\virtualenvs\rasa\lib\site-packages\rasa\core\run.py:131> exception=TimeoutError()>
Traceback (most recent call last):
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\rasa\core\run.py", line 137, in run_cmdline_io
    sender_id=conversation_id,
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\rasa\core\channels\console.py", line 182, in record_messages
    async for response in bot_responses:
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\rasa\core\channels\console.py", line 137, in _send_message_receive_stream
    async for line in resp.content:
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\aiohttp\streams.py", line 39, in __anext__
    rv = await self.read_func()
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\aiohttp\streams.py", line 338, in readline
    await self._wait("readline")
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\aiohttp\streams.py", line 306, in _wait
    await waiter
  File "c:\users\anka\virtualenvs\rasa\lib\site-packages\aiohttp\helpers.py", line 656, in __exit__
    raise asyncio.TimeoutError from None
concurrent.futures._base.TimeoutError
Transport closed @ ('127.0.0.1', 51941) and exception experienced during error handling

Function for sending mail

    def send_email(to_email: Text, content: Text, subject: Text):
        msg = EmailMessage()
        msg['Subject'] = subject
        msg['From'] = EmailSender.EMAIL_ADDRESS
        msg['To'] = to_email
        msg.set_content(content)
        with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
            smtp.login(EmailSender.EMAIL_ADDRESS, EmailSender.EMAIL_PASSWORD)
            smtp.send_message(msg)

Note: Same as OP, my code doesn’t takes 10 sec to execute.

@nik202