question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Object of type SlotSet is not JSON serializable

See original GitHub issue

Rasa 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
harishruparelcommented, Oct 7, 2019

Ran into exactly same issue. No solution. Dear Rasa team, Please suggest a solution… ASAP. unable to use the custom action.

1reaction
akeladcommented, Mar 19, 2019

Thanks for raising this issue, @wochinge will get back to you about it soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object of type SlotSet is not JSON serializable #3090 - GitHub
Rasa 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 ...
Read more >
TypeError: Object of type SlotSet is not JSON serializable
Hi there. Whenever the action server recieves a custom action with the SlotSet function, it gives me the next error:
Read more >
TypeError: Object of type bytes is not JSON serializable
Trying to dump a dictionary in a JSON file gives me the error "TypeError: a bytes-like object is required, not 'str'".
Read more >
JSON serializable Error : r/learnpython - Reddit
Hey Folks, Im working on running code within AWS Lambda. I am using Python 3.9. The overall goal of what I am working...
Read more >
Issue 34858: MappingProxy objects should JSON serialize ...
For the specific case of mappingproxy, there is another issue. Multiple components of a class dict are not all JSON serializable, so you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found