I am trying to fetch data for user queries using custom actions, but it is not working.
Below is my custom action:
class ActionDB(Action):
def name(self):
return ‘action_db’
def run(self, dispatcher, tracker, domain):
import MySQLdb
db = MySQLdb.connect("localhost","root","Abcd_1234","DBforChatbot")
cursor = db.cursor()
PersonID = tracker.get_slot('personid')
q = "select * from Persons where PersonID='{0}' limit 1".format(PersonID)
result = db.query(q)
return [SlotSet("matches", result if result is not None else [])]
and I am getting error as below:
Failed to run custom action ‘action_db’. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-02-28 13:03:08 ERROR rasa_core.processor - Encountered an exception while running action ‘action_db’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2019-02-28 13:03:08 DEBUG rasa_core.processor - Failed to execute custom action.
from future import absolute_import
from future import division
from future import unicode_literals
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
class ActionDB(Action):
def name(self):
return ‘action_db’
def run(self, dispatcher, tracker, domain):
import MySQLdb
db = MySQLdb.connect("localhost","root","Abcd_1234","DBforChatbot")
cursor = db.cursor()
PersonID = tracker.get_slot('personid')
q = "select * from Persons where PersonID='{0}' limit 1".format(PersonID)
result = db.query(q)
return [SlotSet("matches", result if result is not None else [])]
testbot_domain.yml
slots:
personid:
type: text
stockid:
type: text
intents:
greet
bye
affirmative
negative
personid
stockid
inform
entities:
personid
stockid
templates:
utter_greet:
- ‘Hello! How can I help?’
utter_goodbye:
- ‘Talk to you later.’
- ‘Bye bye :(’
utter_ask_personid:
- ‘Tell me your id please’
- ‘May I know your id please?’
utter_ask_stock:
- ‘Tell me the stock name please’
- ‘Could you please tell me the stock name?’
@Ujjwalsas9 try replacing “result = db.query(q)” with “result = cursor.execute(q)” if it doesn’t work try to connect to db using python script. As per my knowledge you are having issue with the db. Make sure you have installed MySQL-python and MySQL-python-connector packages
@mohan Thanks, I tried it but it is not working.
Below is the code which is working on python. But when I am trying to replicate the same with rasa custom actions, it is not working. I think, I am doing something wrong in actions code. Please let me know if you could find the error in my actions code. Thanks for your help.
2019-03-07 17:24:16 ERROR rasa_core.actions.action - Failed to run custom action ‘action_db’. Action server responded with a non 200 status code of 404. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/
2019-03-07 17:24:16 ERROR rasa_core.processor - Encountered an exception while running action ‘action_db’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2019-03-07 17:24:16 DEBUG rasa_core.processor - Failed to execute custom action.
Any ideas on how to get rid of it. FYI: my database is running on port 3306, Rasa action server on 5005 and rasa endpoint is showing 5505.