Object of type SlotSet is not JSON serializable
See original GitHub issueRasa Core version: 0.11.1
Python version: 3.6.5
Operating system (windows, osx, …): Windows 10
Issue: I’m having a problem with a custom action that makes an API call to Apixu Weather API in order to retrieve information about the specific locations weather conditions. When my action server tries to execute the action, I’m getting the following error:
127.0.0.1 - - [2019-03-18 18:40:36] "POST /webhook HTTP/1.1" 500 412 0.148361 DEBUG:rasa_core_sdk.executor:Received request to run 'action_weather' DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): api.apixu.com:80 DEBUG:urllib3.connectionpool:http://api.apixu.com:80 "GET /v1/current.json?key=ab96e96386e149d0b2a153502191803&q=berlin HTTP/1.1" 200 None DEBUG:rasa_core_sdk.executor:Successfully ran 'action_weather' ERROR:flask.app:Exception on /webhook [POST] Traceback (most recent call last): File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function resp = make_response(f(*args, **kwargs)) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\rasa_core_sdk\endpoint.py", line 74, in webhook return jsonify(response) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\json\__init__.py", line 321, in jsonify dumps(data, indent=indent, separators=separators) + '\n', File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\json\__init__.py", line 179, in dumps rv = _json.dumps(obj, **kwargs) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\__init__.py", line 399, in dumps **kw).encode(obj) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\encoder.py", line 296, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\encoder.py", line 378, in iterencode return _iterencode(o, 0) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\json\__init__.py", line 81, in default return _json.JSONEncoder.default(self, o) File "C:\Users\Manue\AppData\Local\Programs\Python\Python36\lib\site-packages\simplejson\encoder.py", line 273, in default o.__class__.__name__) TypeError: Object of type SlotSet is not JSON serializable 127.0.0.1 - - [2019-03-18 18:40:58] "POST /webhook HTTP/1.1" 500 412 0.137061
Please help me to find a solution, i have tried some stuff from other peoples issues that got the same Error but nothing has helped yet.
Thanks for any kind of help. You can see the actions.py
right here:
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import logging
from rasa_core_sdk import Action
from rasa_core_sdk.events import UserUtteranceReverted
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 = "MY_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)]`
Content of domain file (if used & relevant):
slots:
location:
type: text
intents:
- greet
- goodbye
- inform
entities:
- location
templates:
utter_greet:
- "Hello! How can i help you?"
utter_goodbye:
- "See you!"
- "Goodbye."
- "See you next time."
utter_ask_location:
- "For what location do you want to receive weather data?"
actions:
- utter_greet
- utter_goodbye
- utter_ask_location
- action_weather
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Ran into exactly same issue. No solution. Dear Rasa team, Please suggest a solution… ASAP. unable to use the custom action.
Thanks for raising this issue, @wochinge will get back to you about it soon.