Here is my action.py file code
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from typing import Any, Text, Dict, List
from rasa_core_sdk import Action
from rasa_sdk import Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_core_sdk.events import SlotSet
import mysql.connector
class ActionSqlfetch(Action):
def name(self):
return "action_db"
def run(self, dispatcher, tracker: Tracker, domain: Dict[Text, Any]):
mydb = mysql.connector.connect(host="localhost",
user="root",
passwd="5000",
database="world",
auth_plugin='mysql_native_password'
)
mycursor = mydb.cursor()
patient_id = int(tracker.get_slot('patientid'))
sql = " Select * from genral_ward where patient_id = '%d' " % patient_id
try:
mycursor.execute(sql)
if mycursor.execute(sql) == 0:
print("Sorry could not find the relevent data, please check your id")
result = mycursor.fetchone()
for row in result:
name = row[1]
gender = row[2]
disease = row[3]
cost = row[7]
patient = ("Patient Id =%d, Name = %s, Gender = %s, Disease =%s, Cost = %d" % (patient_id, name, gender, disease, cost))
print(patient)
except:
dispatcher.utter_message("Error fetching data")
finally:
mydb.close()
#response = " ""The details is follows"" ".format(result)
dispatcher.utter_message("Here are the details, name:{}, disease:{}".format(name,disease))
return [SlotSet('patientid',patient_id)]
and I’m getting this error
dispatcher.utter_message("Here are the details, name:{}, disease:{}".format(name,disease))
UnboundLocalError: local variable 'name' referenced before assignment
127.0.0.1 - - [2020-04-07 13:40:47] "POST /webhook HTTP/1.1" 500 426 0.281024
Please help me, I need to do this project urgent