Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: main is not JSON serializable from REST api #1264

Closed
gschrader opened this issue Oct 5, 2016 · 7 comments
Closed

TypeError: main is not JSON serializable from REST api #1264

gschrader opened this issue Oct 5, 2016 · 7 comments

Comments

@gschrader
Copy link
Contributor

I'm trying to see if I can create my tables using the REST api discussed in #279 however when I access the /tablemodelview/api/read endpoint I get the following exception.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2000, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1991, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1567, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python2.7/site-packages/flask_appbuilder/security/decorators.py", line 52, in wraps
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/flask_appbuilder/views.py", line 229, in api_read
    result=result)
  File "/usr/local/lib/python2.7/site-packages/flask/json.py", line 266, in jsonify
    (dumps(data, indent=indent, separators=separators), '\n'),
  File "/usr/local/lib/python2.7/site-packages/flask/json.py", line 126, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/simplejson/__init__.py", line 397, in dumps
    **kw).encode(obj)
  File "/usr/local/lib/python2.7/site-packages/simplejson/encoder.py", line 275, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/lib/python2.7/site-packages/simplejson/encoder.py", line 357, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python2.7/site-packages/flask/json.py", line 83, in default
    return _json.JSONEncoder.default(self, o)
  File "/usr/local/lib/python2.7/site-packages/simplejson/encoder.py", line 252, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: main is not JSON serializable

Any ideas what the problem might be?

@gschrader
Copy link
Contributor Author

Unfortunately this still occurs in version 0.11.

@gschrader
Copy link
Contributor Author

This is still an issue in 0.12, I'd like to be able to help but I'm failing to see the main variable being defined in TableModelView.

@gschrader
Copy link
Contributor Author

Still occurs in 17.6, I'm guessing that nobody actually uses the REST api for this sort of thing. I guess I'll see what my other options are to automate creating tables.

@gschrader
Copy link
Contributor Author

I'm opting to write to the sqllite database directly.

@eeve
Copy link
Contributor

eeve commented May 17, 2017

I also encountered this error

http://0.0.0.0:8088/druiddatasourcemodelview/api/read endpoint throw is not JSON serializable

stack:

...
...
File "/usr/local/superset/venv/lib/python3.5/site-packages/simplejson/encoder.py", line 697, in _iterencode
    o = _default(o)
  File "/usr/local/superset/venv/lib/python3.5/site-packages/flask/json.py", line 80, in default
    return _json.JSONEncoder.default(self, o)
  File "/usr/local/superset/venv/lib/python3.5/site-packages/simplejson/encoder.py", line 268, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: data_demo is not JSON serializable

@mistercrunch
Copy link
Member

mistercrunch commented May 17, 2017

I've found that to make the free REST api usable in FAB, we often have to create an alternate ModelView for it.

For example, for the Dashboard model, we create a ModelView for the CRUD here:
https://github.com/airbnb/superset/blob/master/superset/views/core.py#L133

Then we create another ModelView for the REST API that exposes a different set of columns:
https://github.com/airbnb/superset/blob/master/superset/views/core.py#L504

I don't think that the REST api we get for free out of FAB is super mature and I think we've only used it for read operations. Note that the URL mini-language (for filtering and sorting) isn't documented but is easy to reverse-engineer in the CRUD UI. By setting filters and sorting the table, you can look at the URL and copy paste that into your /api/read? queries

@gschrader
Copy link
Contributor Author

@mistercrunch some of the api does actually work fine for read, however tablemodelview and apparently druiddatasourcemodelview throws the error.

@dpgaspar dpgaspar mentioned this issue Feb 11, 2020
12 tasks
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 17, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 24, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 25, 2021
zhaoyongjie pushed a commit to zhaoyongjie/incubator-superset that referenced this issue Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants