Help please In action server error is AttributeError: ‘ApixuClient’ object has no attribute ‘getcurrent’ and in shell error is - 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.
looks like you have some error in your action code. I did the weather bot before you may refer to my code below:
class ActionWeather(Action):
def name(self):
return "action_weather"
def run(self, dispatcher,tracker,domain):
api_key = 'INSERT YOUR OWN KEY'#your apixu key
loc = tracker.get_slot('location') #obtain slot
api_address='http://api.apixu.com/v1/current.json?key={}&q={}'.format(api_key,loc) #for json data
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']
#dispatcher.utter_message("You said " +tracker.latest_message["text"])
#output sentence format
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)
#SlotSet('location',loc)
return [AllSlotsReset()]
Oh thank you ! I had not configured properly
I have followed your code @gcgloven, I am getting the error: TabError: inconsistent use of tabs and spaces in indentation
I am using Python 3.7 and Rasa 1.3.3. Want to know if I have to modify somewhere.
class ActionWeather(Action):
def name(self):
return "action_weather"
def run(self, dispatcher,tracker,domain):
api_key = 'INSERT YOUR OWN KEY'#your apixu key
loc = tracker.get_slot('location') #obtain slot
api_address='http://api.apixu.com/v1/current.json?key={}&q={}'.format(api_key,loc) #for json data
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']
#dispatcher.utter_message("You said " +tracker.latest_message["text"])
#output sentence format
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)
#SlotSet('location',loc)
return [AllSlotsReset()]
Hi sorry for the delayed replay. Back then my configuration fo spaces and tabs are mixed… cuz I just started using notepad as IDE… updated if you still have issue, it’s just the problem with the spacings
Hi ,
For current = requests.get(api_address).json()
i am getting following error
File “C:\Users\aashay.bane\AppData\Local\Continuum\anaconda3\envs\combined_action\lib\site-packages\requests\adapters.py”, line 123, in init super(HTTPAdapter, self).init()
TypeError: super(type, obj): obj must be an instance or subtype of type
Thank you
Hi did you resolve the issue?
just restart your kernal , It worked for me
okay. Im getting this error now
country = current['location']['country']
KeyError: ‘location’
Hey , current is your main dict, within it u have diff list .
check the spacing and spellings.
also try country = current[‘location’][‘country’]
regards, Aashay
Your input -> hi
Hello! How can I help?
Your input -> What’s the weather in london?
2020-01-15 13:13:53 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.
Still getting error.
hey pratik you need to check the action weather in python , and see if its working there.
i used the above code too
can you past the custome action code
class ActionWeather(Action):
def name(self):
return "action_weather"
def run(self, dispatcher,tracker,domain):
api_key = ""#your apixu key
loc = tracker.get_slot('location') #obtain slot
api_address="http://api.apixu.com/v1/current.json?key={}&q={}".format(api_key,loc) #for json data
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']
#dispatcher.utter_message("You said " +tracker.latest_message["text"])
#output sentence format
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)
#SlotSet('location',loc)
return [AllSlotsReset()]
class ActionWeather(Action): def name(self): return ‘action_weather’
def run(self, dispatcher, tracker, domain):
from apixu.client import ApixuClient
import requests
api_key = 'Your APi KEY' #your apixu key
client = ApixuClient(api_key)
loc = tracker.get_slot('location')
api_address='http://api.weatherstack.com/current?access_key={}&query={}'.format(api_key,loc) #for json data
current = requests.get(api_address).json()
#current = client.getcurrent(q=loc)
country = current['location']['country']
city = current['location']['name']
#condition = current['current']['condition']['text']
temperature_c = current['current']['temperature']
humidity = current['current']['humidity']
wind_mph = current['current']['wind_speed']
response = """In {} at the moment. The temperature is {}' degrees, the humidity is {}% and the wind speed is {} mph.""".format( city, temperature_c, humidity, wind_mph)
dispatcher.utter_message(response)
return [SlotSet('location',loc)]
try with this , what version of rasa are you using ?
rasa version 1.0.9
Thanks for the help bro solved it.
welcome !!!
@Aashay1 I am using rasa 1.0.9 and followed the tutorial. nlu train is working well. getting the following error:
Your input -> whats the weather at London
2020-02-05 13:43:37 DEBUG rasa.core.agent - Created a new lock for conversation ‘default’
2020-02-05 13:43:37 DEBUG rasa.core.tracker_store - Recreating tracker for id ‘default’
2020-02-05 13:43:37 DEBUG rasa.core.processor - Received user message ‘whats the weather at London’ with intent ‘{‘name’: ‘inform’, ‘confidence’: 0.8830060964655023}’ and entities ‘[]’
2020-02-05 13:43:37 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 10 events
2020-02-05 13:43:37 DEBUG rasa.core.policies.memoization - Current tracker state [{‘intent_greet’: 1.0, ‘prev_action_listen’: 1.0}, {‘prev_utter_greet’: 1.0, ‘intent_greet’: 1.0}, {‘intent_greet’: 1.0, ‘prev_action_listen’: 1.0}, {‘prev_action_listen’: 1.0, ‘intent_inform’: 1.0}, {‘prev_action_listen’: 1.0, ‘intent_inform’: 1.0}]
2020-02-05 13:43:37 DEBUG rasa.core.policies.memoization - There is no memorised next action
2020-02-05 13:43:37 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_1_KerasPolicy
2020-02-05 13:43:37 DEBUG rasa.core.processor - Predicted next action ‘action_listen’ with confidence 0.43.
2020-02-05 13:43:37 DEBUG rasa.core.processor - Action ‘action_listen’ ended with events ‘[]’
2020-02-05 13:43:37 DEBUG rasa.core.agent - Deleted lock for conversation ‘default’ (unused)