Problem with Custom Action

Hi!,I try to run my bot but appears this problem: “Encountered an exception while running action ‘search_contratti’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

Before I have run the commands to activate the action server: python -m rasa_core_sdk.endpoint --actions actions (and I don’t have problem with it, because at the end the output is “Action endpoint is up and running. on”)

It’s possible that my code in custom action is not so good, because it’s my first time with Rasa and Sql Server. I post my script so you can see if there is any kind of errors:

actions.py

def name(self): return “search_contratti”

def run(self, dispatcher, tracker, domain):
    filter = tracker.get_slot("tipo_contratto")
    conn = pyodbc.connect(
        'DRIVER={###};SERVER=## ;PORT=##;DATABASE=##;UID=##;PWD=##')
    dispatcher.utter_message("Sto cercando il contratto")
    cursor = conn.cursor()
    return cursor.execute('SELECT TOP 5 *  FROM [##].[##].[##] '
                          ' where c=58 and GRP2 like ?', SlotSet("matches", filter)).fetchall()

This is the first, there is another action but the code is almost the same but if can help I’ll also post the other custom action. I’ll try different solution but the problem is always the same. Thank you and sorry for my bad English but I’m Italian and I’m studying to improve it.

Thank you very much, Daniela

You need to use utter_message not return all the data from the database.

def run(self, dispatcher, tracker, domain):
    filter = tracker.get_slot("tipo_contratto")
    conn = pyodbc.connect(
        'DRIVER={###};SERVER=## ;PORT=##;DATABASE=##;UID=##;PWD=##')
    dispatcher.utter_message("Sto cercando il contratto")
    cursor = conn.cursor()
    data = cursor.execute('SELECT TOP 5 *  FROM [##].[##].[##] '
                          ' where c=58 and GRP2 like ?', SlotSet("matches", filter)).fetchall()
   dispatcher.utter_message(data)
   return

I have just tried this solution but the problem is the same:

This is my endpoint.yml:

action_endpoint: ** url: “http://localhost:8081/webhook”**

But I don’t thing there are problem here. Thank’s

Moreover during the code execution there is this message:

Rasa Core server is up and running on http://localhost:5005

It’s a problem if Rasa Core is on a different server? Sorry if my question are stupid but I really try different solutions and I don’t resolve the problem

No that is not the problem. Can you show the error logs from the terminal window where your action file is running?

Do you say this one?

or not?

I also have another propmt open with the action server on :

At the same time I have a script running on PyCharm, because for my action_endpoint I use a Http Server. This is the script:

class HttpServer(SimpleHTTPRequestHandler):

def ok(self, text: str):
    self.send_response(200)
    self.send_header('Content-type', 'text/html')
    self.end_headers()
    self.wfile.write(bytes(text, "utf8"))

def do_POST(self):
    try:

        self.data_string = self.rfile.read(int(self.headers['Content-Length']))

        self.data = simplejson.loads(self.data_string)

        self.send_response(200)
        self.end_headers()

    except ValueError:
        self.ok("{'Error': 'Errore elaborazione richiesta'}")
        print(ValueError)

def run(): print(‘Avvio del server…’) server_address = (‘127.0.0.1’, 8081) httpd = HTTPServer(server_address, HttpServer) httpd.serve_forever()

run()

ok, in the last picture that I post the action server seems to be 5055. So I change the action_endpoint in the endpoint.yml. It’s strange because I decide to use a Http Server because before the action doesn’t run. Now, after this change, this is the situation:

It doesn’t show problems fortunatly.

So if I understand you correctly, the problem is solved?

Not really, because now there aren’t errors but anyway the action doesn’t give anything in return :frowning: I don’t understand why. If you look at the first picture, after a custom action this is the answer

(‘Invalid parameter type. param-index=0 param-type=type’, ‘HY105’): 127.0.0.1 - - [2019-05-16 15:55:16] “POST /webhook HTTP/1.1” 200 196 0.001941

How to change server action from 5055 to another? Because the action server that I want isn’t 5055, in my endpoint.yml there is the right localhost but when I run the comand python -m rasa_core_sdk.endpoint --actions actions it run the action on the 5055 server :frowning:

hello,have you solved your problem?I think I just met the same problem as you did. I used the ‘–debug’ in the interactive learning mode,so my error logs shown like this:

Could you give me some advice?

@DanielaMilo The endpoint.yml should refer to the port where the action server is running. So you can’t set the port number in the endpoint file.

The default port where the action server is running, is 5055. This is defined in the rasa_core_sdk.endpoint. You could change the number there, but I’m not sure why you wouldn’t want your action file to run on 5055.

In the pictures of the post where you said you changed the action_endpoint in the endpoint.yml to 5055, there seems to be some sort of problem with your action file. the message: (“Invalid parameter type, param-index-0 param-type=type”, “HY105”) shouldn’t be there.

Could you try to run a simple custom action? For example

class ActionTest(Action):
  def name(self):
    return "action_test"
     
  def run(self, dispatcher, tracker, domain):
    dispatcher.utter_message("Just a test to check if my action server is working correctly")

@shenjw Can you also show a picture of the terminal window where the action server is running?

Thank you for the answers. I solved my problem: when I activate the action server use this command: python -m rasa_core_sdk.endpoint --actions actions -p 8081 In this way the action server run on the port that I want.

thanks for your reply, I’ve already solved my problem, when I written my actions, I returned a string in my run() method, and that’s why I got the exception. So I change to return [], everything does well now