Issue with database and RASA connection
See original GitHub issueRasa Core version: 0.13.0
Python version: 0.14.1
Operating system (windows, osx, …): Linux
Issue: I am facing some issues while trying to fetch data from MySQL database.
I am getting an error as follows:
2019-03-11 17:37:50 DEBUG rasa_core.processor - Predicted next action ‘action_db’ with prob 1.00. 2019-03-11 17:37:50 DEBUG rasa_core.actions.action - Calling action endpoint to run action ‘action_db’. 2019-03-11 17:37:50 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-11 17:37:50 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-11 17:37:50 DEBUG rasa_core.processor - Failed to execute custom action.
Content of domain file (if used & relevant):
slots:
personid:
type: text
stockid:
type: text
matches:
type: unfeaturized
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?'
actions:
- utter_greet
- utter_goodbye
- utter_ask_stock
- utter_ask_personid
- action_db
Content of action file :
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
import MySQLdb
class ActionDb(Action):
def name(self):
return "action_db"
def run(self, dispatcher, tracker, domain):
db = MySQLdb.connect("localhost","root","root","DBforChatbot")
cursor = db.cursor()
PersonID = tracker.get_slot('personid')
StockID = tracker.get_slot('stockid')
q = "select StockName, StockBalance from Persons WHERE (PersonID = '%d' and StockName = '%s');" % (PersonID, StockID)
try:
cursor.execute(q)
if cursor.execute(q)==0:
print("Sorry, could not find any relevant data. Please contact 1234 for further assistance.")
results = cursor.fetchall()
not all(results)
for row in results:
stockname = row[0]
stockbal = row[1]
# Now print fetched result
details = ("stockname=%s,stockbal=%d" % (stockname,stockbal))
print(details)
except:
print ("Error: unable to fetch data")
db.close()
response = """The detail is as follows {}.""".format(results)
dispatcher.utter_message(response)
return [SlotSet('stockid',StockID)]
Content of endpoints file (if used & relevant):
action_endpoint:
url: "http://localhost:5055/webhook/"
Content of dialogue_management_model file:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
import rasa_core
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.utils import EndpointConfig
from rasa_core.run import serve_application
from rasa_core import config
logger = logging.getLogger(__name__)
def train_dialogue(domain_file = 'testbot_domain.yml',
model_path = './models/dialogue',
training_data_file = './data/stories.md'):
agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(max_history=3, epochs=200, batch_size=50)])
data = agent.load_data(training_data_file)
agent.train(data)
agent.persist(model_path)
return agent
def run_test_bot(serve_forever=True):
interpreter = RasaNLUInterpreter('./models/nlu/default/testbotnlu')
action_endpoint = EndpointConfig(url="http://localhost:5055/webhook/")
agent = Agent.load('./models/dialogue', interpreter=interpreter, action_endpoint=action_endpoint)
rasa_core.run.serve_application(agent ,channel='cmdline')
return agent
if __name__ == '__main__':
train_dialogue()
run_test_bot()
Hi @tmbo @akelad @EPedrotti , could you please help here. Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (3 by maintainers)
Top GitHub Comments
Hi Ujjwalsas9 can you elaborate what you fixed to get this resolved.
Can @Ujjwalsas9 please tell me what you fixed in this? I am doing similar kind of thing.