0

Rasa version: 1.10.1

I'm building a weatherbot in Rasa using custom actions and am facing issues in the actions.py file.

While testing the dialogue model using rasa shell / rasa interative , I'm receiving an error ' Key Error : 'location ' in country = current['location']['country'] , when I perform a query like ' Tell me the weather in Paris' . The entity is extracted correctly as Paris(location) and the slot(for location) is also filled . What could be causing this error given that the entity is correctly extracted ?

enter image description here

The terminal running rasa run actions shows the following error :

Exception occurred while handling uri: 'http://localhost:5055/webhook/'
Traceback (most recent call last):
  File "c:\users\91887\anaconda3\envs\myenv\lib\site-packages\sanic\app.py", line 976, in handle_request
    response = await response
  File "c:\users\91887\anaconda3\envs\myenv\lib\site-packages\rasa_sdk\endpoint.py", line 102, in webhook
    result = await executor.run(action_call)
  File "c:\users\91887\anaconda3\envs\myenv\lib\site-packages\rasa_sdk\executor.py", line 387, in run
    events = action(dispatcher, tracker, domain)
  File "D:\Data Mining\Mini Projects\WeatherBot\actions.py", line 15, in run
    country = current['location']['country']
KeyError: 'location'

My actions.py :

from rasa_sdk import Action
from rasa_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 = '********'
        client = ApixuClient(api_key)

        loc = tracker.get_slot('location')
        current = client.current(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)]


My config.yml file :

language: "en"
pipeline: "pretrained_embeddings_spacy"

policies:
  - name: MemoizationPolicy
  - name: KerasPolicy
    epochs: 200
  - name: MappingPolicy

What could be causing this error?

pppery
  • 3,731
  • 22
  • 33
  • 46
Bharathi
  • 201
  • 1
  • 8
  • 1
    This error is not belongs to rasa. check the response of ApixuClient. without rasa actions, print the response and check the keys. – Madusudhanan Jun 14 '20 at 17:13
  • It appears that you have posted sensitive/private information. Please reset your passwords and/or revoke API keys and tokens, as they are considered compromised when posted on the internet. If personally-identifiable information was posted, please [edit] out the info then flag your post for a moderator to redact the revisions. – Samuel Liew Jun 17 '20 at 02:40
  • am agreeing with Madusudhanan, the error doesn't belong to RASA, It might be your current dict has not a Key named 'location', A Python KeyError exception is what is raised when you try to access a key that isn’t in a dictionary (dict) https://stackoverflow.com/questions/10116518/im-getting-key-error-in-python – Sameesh Jun 21 '20 at 04:04

0 Answers0