Skip to content

TypeError: Object of type float32 is not JSON serializable #77

@AmitPal95

Description

@AmitPal95

I get the following error while running a custom made environment or any predefined environment like CartPole-v0 (I am trying to use the CPP binding, but also I get a similar error with "python example_agent.py"):-

./test1

ERROR: bad HTTP response code, and also cannot parse server message:

<title>500 Internal Server Error</title>

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

python gym_http_server.py

Server starting at: http://127.0.0.1:5000
[2021-01-21 15:31:17,337] ERROR in app: Exception on /v1/envs/ff0e588b/action_space/ [GET]
Traceback (most recent call last):
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functionsrule.endpoint
File "gym_http_server.py", line 278, in env_action_space_info
return jsonify(info = info)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/json.py", line 266, in jsonify
(dumps(data, indent=indent, separators=separators), '\n'),
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/json.py", line 126, in dumps
rv = _json.dumps(obj, **kwargs)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/init.py", line 238, in dumps
**kw).encode(obj)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/site-packages/flask/json.py", line 83, in default
return _json.JSONEncoder.default(self, o)
File "/home/amit/miniconda3/envs/cobel-spike-http-v6/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type float32 is not JSON serializable

Kindly help me understand the problem and how to solve it.

I have -
Flask 0.11.1
Flask-Compress 1.4.0
Flask-SocketIO 2.9.6
gym 0.12.4
numpy 1.16.3
pip 19.1.1
pytest 6.2.1
requests 2.25.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions