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