No response from RestInput on running custom actions

I have already posted the issue on Github but I am hoping somebody here might be able to help me as well!

Rasa Core version: 0.12.3 Python version: Python 3.6.5 :: Anaconda, Inc. Operating system (windows, osx, …): MacOS

Issue: I have made a basic bot with 5 intents and 2 custom actions. The bot runs perfectly fine while I run it on my cmdline and it is making the appropriate API calls through the custom actions as I want it to.

I am trying to use the RestInput channel to extend my bot’s domain. I have followed the instructions in the documentation. I run the following command, I have also tried using different ports

python -m rasa_core.run -d models/dialogue -u models/nlu/current  --port 5002 --credentials credentials.yml

I also had my custom actions running with this command

python -m rasa_core_sdk.endpoint --actions actions

I also have my credentials file defined as described in the docs. I am using postman to POST user inputs and get a response back at the following address: http://localhost:5002/webhooks/rest/webhook

Now I am able to get a response back for the basic “greet” intent as I expect it to be. But when I follow that up with another input which is supposed to run a custom action for me, I just get a [ ] response back and an exception error, I tried that for both my custom actions. Just to remind you these custom actions work perfectly fine on the cmdline.

Here is the exception error I get, it is also followed by a 200

2018-12-26 22:59:20 ERROR    rasa_core.processor  - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2018-12-26 22:59:20] "POST /webhooks/rest/webhook HTTP/1.1" 200 110 0.026883

Am I missing something that needs to be done here? Or is this a bug? How else would you suggest doing it? Do I need to import something somewhere in my actions.py file or the main dialogue runner file? I would be happy to see an example which works, I just want to connect my very basic bot to a web UI but right now I am just trying to get responses back.

I don’t think I need to post my files for this since I have cross checked it is working on the cmdline.

Hi @samarth12, the error is in your custom action. Could you please share the error stack of your actions server?

@EPedrotti I am not sure how it is going wrong in the custom actions, because the custom actions seem to be working perfectly fine while I run them on the cmd line. That is leaving me confused, or may be I am missing something rudimentary here. I am posting all the details below, I also have this as an open issue on github.

Actions SDK just returns a 404 error whenever the APIs need to be called, the thing I do not get is that works perfectly fine on the cmd line.

INFO:__main__:Starting action endpoint server...
INFO:rasa_core_sdk.executor:Registered function for 'action_weather'.
INFO:rasa_core_sdk.executor:Registered function for 'wolfram_alpha'.
INFO:__main__:Action endpoint is up and running. on ('0.0.0.0', 5055)
127.0.0.1 - - [2019-01-01 12:00:27] "POST /webhook/ HTTP/1.1" 404 342 0.009915
127.0.0.1 - - [2019-01-01 12:00:53] "POST /webhook/ HTTP/1.1" 404 342 0.001687

Here are my localhost logs

2019-01-01 12:00:27 ERROR    rasa_core.actions.action  - Failed to run custom action 'action_weather'. 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-01-01 12:00:27 ERROR    rasa_core.processor  - Encountered an exception while running action 'action_weather'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2019-01-01 12:00:27] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.077290
2019-01-01 12:00:53 WARNING  py.warnings  - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  if diff:

2019-01-01 12:00:53 ERROR    rasa_core.actions.action  - Failed to run custom action 'wolfram_alpha'. 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-01-01 12:00:53 ERROR    rasa_core.processor  - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
127.0.0.1 - - [2019-01-01 12:00:53] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.073290

You can see I tried calling both the APIs and get the same error. Also if I didn’t mention before, everything other than API calls is returning a response on postman as it should.

Here are more detailed logs. My first input is: “Hello my name is Mark”. I get a response back, my next input is: “Who is the president of US?” where it should call the Wolfram API. The same thing happens with weather API if I change my input to: “What is the weather in London?”

2019-01-01 12:18:44 INFO     root  - Rasa Core server is up and running on http://localhost:5005
Bot loaded. Type a message and press enter (use '/stop' to exit): 
2019-01-01 12:18:57 DEBUG    rasa_core.tracker_store  - Creating a new tracker for id 'Rasa'.
2019-01-01 12:18:57 WARNING  py.warnings  - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  if diff:

2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Received user message 'Hello my name is Mark' with intent '{'name': 'greet', 'confidence': 0.5992243649211548}' and entities '[{'start': 17, 'end': 21, 'value': 'mark', 'entity': 'PERSON', 'confidence': 0.6440988744205052, 'extractor': 'ner_crf'}]'
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Logged UserUtterance - tracker now has 3 events
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Current slot values: 
	PERSON: mark
	location: None
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - Current tracker state [None, None, None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:18:57 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Predicted next action 'utter_greet' with prob 0.30.
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Action 'utter_greet' ended with events '[]'
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Bot utterance 'BotUttered(text: Hello mark! How can I help?, data: {
  "elements": null,
  "buttons": null,
  "attachment": null
})'
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - Current tracker state [None, None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:18:57 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:18:57 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Predicted next action 'action_listen' with prob 0.87.
2019-01-01 12:18:57 DEBUG    rasa_core.processor  - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2019-01-01 12:18:57] "POST /webhooks/rest/webhook HTTP/1.1" 200 203 0.257879
2019-01-01 12:19:51 DEBUG    rasa_core.tracker_store  - Recreating tracker for id 'Rasa'
2019-01-01 12:19:52 WARNING  py.warnings  - /anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
  if diff:

2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Received user message 'Who is the president of US' with intent '{'name': 'information', 'confidence': 0.6909834200535575}' and entities '[]'
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Logged UserUtterance - tracker now has 7 events
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Current slot values: 
	PERSON: mark
	location: None
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - Current tracker state [None, {}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_action_listen': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:19:52 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Predicted next action 'wolfram_alpha' with prob 0.70.
2019-01-01 12:19:52 DEBUG    rasa_core.actions.action  - Calling action endpoint to run action 'wolfram_alpha'.
2019-01-01 12:19:52 ERROR    rasa_core.actions.action  - Failed to run custom action 'wolfram_alpha'. 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-01-01 12:19:52 ERROR    rasa_core.processor  - Encountered an exception while running action 'wolfram_alpha'. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Failed to execute custom action.
Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 338, in run
    response.raise_for_status()
  File "/anaconda3/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: NOT FOUND for url: http://localhost:5055/webhook/

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/anaconda3/lib/python3.6/site-packages/rasa_core/processor.py", line 351, in _run_action
    events = action.run(dispatcher, tracker, self.domain)
  File "/anaconda3/lib/python3.6/site-packages/rasa_core/actions/action.py", line 358, in run
    raise Exception("Failed to execute custom action.")
Exception: Failed to execute custom action.
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Action 'wolfram_alpha' ended with events '[]'
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - Current tracker state [{}, {'entity_PERSON': 1.0, 'prev_action_listen': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'prev_utter_greet': 1.0, 'entity_PERSON': 1.0, 'intent_greet': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_action_listen': 1.0, 'slot_PERSON_0': 1.0}, {'intent_information': 1.0, 'prev_wolfram_alpha': 1.0, 'slot_PERSON_0': 1.0}]
2019-01-01 12:19:52 DEBUG    rasa_core.policies.memoization  - There is no memorised next action
2019-01-01 12:19:52 DEBUG    rasa_core.policies.ensemble  - Predicted next action using policy_1_KerasPolicy
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Predicted next action 'action_listen' with prob 0.98.
2019-01-01 12:19:52 DEBUG    rasa_core.processor  - Action 'action_listen' ended with events '[]'
127.0.0.1 - - [2019-01-01 12:19:52] "POST /webhooks/rest/webhook HTTP/1.1" 200 142 0.094410

And I will also attach my custom actions file, it just making two API calls.

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 ActionWeather(Action):
	def name(self):
		return 'action_weather'
		
	def run(self, dispatcher, tracker, domain):
		from apixu.client import ApixuClient
		api_key =  #your apixu key
		client = ApixuClient(api_key)
		
		loc = tracker.get_slot('location')
		current = client.getCurrentWeather(q=loc)
		
		country = current['location']['country']
		city = current['location']['name']
		condition = current['current']['condition']['text']
		temperature_c = current['current']['temp_c']
		humidity = current['current']['humidity']
		wind_mph = current['current']['wind_mph']

		response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)
						
		dispatcher.utter_message(response)
		return [SlotSet('location',loc)]

class Wolfram(Action):
	def name(self):
		return 'wolfram_alpha'
		
	def run(self, dispatcher, tracker, domain):
		import wolframalpha
		app_id = "api_key"
		input = tracker.latest_message["text"]
		print(input)
		client = wolframalpha.Client(app_id)
		res = client.query(input)
		answer = next(res.results).text
		response = answer
		dispatcher.utter_message(response)
		return
    raise Exception("Failed to execute custom action.")
Exception: Failed to execute custom action.```

For some reason the custom action is failing, do you have the stack trace of the action server error? Or, could you debug you custom action by attaching to the process and see what is wrong? You can do this using PyCharm

@EPedrotti I finally figured out the problem I was running into! It was very stupid and needed another eye to look into my errors. My endpoints.yml file was redirecting towards url: "http://localhost:5055/webhook/" which works fine with the cmd line. But apparently, the REST input calls to url: "http://localhost:5055/webhook" .

Notice the “/” after webhook.

1 Like

@samarth12 glad you solved it!

1 Like

hey @samarth12 Is it necessary to use dokcer? i am using rasa 0.12.0 ,nlu 0.13.8 and rasa_core_sdk 0.12.1. and i am not using docker. i want to run custom actions on local server. plz help me with this error

2019-01-15 17:49:09 DEBUG rasa_core.processor - Predicted next action ‘action_fill_size’ with prob 0.63. 2019-01-15 17:49:09 ERROR rasa_core.processor - Encountered an exception while running action ‘action_fill_size’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. 2019-01-15 17:49:09 ERROR rasa_core.processor - The model predicted the custom action ‘action_fill_size’ but you didn’t configure an endpoint to run this custom action. Please take a look at the docs and set an endpoint configuration. Actions

@pragya-96 Do you have an endpoints.yml file in your folder? If not please make one as explained in the documentation, that basically connects your RASA api to the custom actions. Remember to pass the endpoints flag in the run command as well.