Getting error mesasage when running Custom action

Hi guys,

I’m getting the following error when i interact with the bot

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.

KeyError: ‘location’

@pratikh07 could you post the full log of the error? Seems like you have a bug in the code of your action

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
	loc = tracker.get_slot('location')
	#client = ApixuClient(api_key)
	api_address='http://api.apixu.com/v1/current.json?key={}&q={}'.format(api_key,loc)
	
	
	current = requests.get(api_address).json()
	
	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)]
	return [AllSlotsReset()]

Rasa shell gives this output:

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.

Rasa run actions gives this error:

2020-01-15 10:15:45 ERROR rasa_sdk.endpoint - Exception on /webhook [POST] Traceback (most recent call last): File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask/app.py”, line 2446, in wsgi_app response = self.full_dispatch_request() File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask/app.py”, line 1951, in full_dispatch_request rv = self.handle_user_exception(e) File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask_cors/extension.py”, line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask/app.py”, line 1820, in handle_user_exception reraise(exc_type, exc_value, tb) File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask/_compat.py”, line 39, in reraise raise value File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask/app.py”, line 1949, in full_dispatch_request rv = self.dispatch_request() File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask/app.py”, line 1935, in dispatch_request return self.view_functionsrule.endpoint File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/flask_cors/decorator.py”, line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/rasa_sdk/endpoint.py”, line 59, in webhook response = executor.run(action_call) File “/home/phanee/Weather/myenv/venv/lib/python3.6/site-packages/rasa_sdk/executor.py”, line 245, in run events = action(dispatcher, tracker, domain) File “/home/phanee/Weather/Weather_bot/actions.py”, line 23, in run country = current[‘location’][‘country’] KeyError: ‘location’

Thanks @akelad i resolved it.

@akelad : Hi, I am building weather chatbot and I am encountering the following error

Traceback (most recent call last): File “c:\users\iarya\anaconda3\envs\chatbot\lib\site-packages\sanic\app.py”, line 976, in handle_request response = await response File “c:\users\iarya\anaconda3\envs\chatbot\lib\site-packages\rasa_sdk\endpoint.py”, line 102, in webhook result = await executor.run(action_call) File “c:\users\iarya\anaconda3\envs\chatbot\lib\site-packages\rasa_sdk\executor.py”, line 389, in run events = action(dispatcher, tracker, domain) File “C:\Office_WorkFiles\rasabot\actions.py”, line 16, in run country = current[‘location’][‘country’] KeyError: ‘location’

Hi @ishanarya14,

Print out the

loc

variable and see if its not empty or not

In your post at the end it says KeyError: ‘location’. KeyError is raised when a mapping key is accessed and isn’t found in the mapping.

-Murali

Hi @MuraliChandran14, thanks for the reply. i figured the issue.

Right now i am facing issue with Slack enable events

@ishanarya14 Can you please tell me how you resolved it ? I’m getting the same error ’ KeyError: ‘location’ ’ . Thanks

Hey @Bharathi-A-7 , try with this file actions.py (1.3 KB)

Thanks

@ishanarya14 Thanks a lot !