Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Type Error: 4.8000002 is not JSON serializable #73

Description

@AndreasRigas

Minimal Scala code request

private val contentType = ContentTypes.`application/json` //Data Content Type

  def requestToApi(request: gymApi): HttpResponse = {
  val url = "http://127.0.0.1" + ":" + 5000 + request.url
  val httpRequest = HttpRequest(uri = url).withMethod(request.method).withEntity(HttpEntity(contentType, """{}"""))
  val responseFuture: Future[HttpResponse] = Http().singleRequest(httpRequest)
  Await.result(responseFuture, timeout.second)
}

response match {
  case HttpResponse(StatusCodes.OK, headers, entity, _) => println(entity.toString())
}

Error:

  [2019-03-05 22:25:49,624] ERROR in app: Exception on /v1/envs/5d5aee73/observation_space/ [GET]
Traceback (most recent call last):
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "gym_http_server.py", line 340, in env_observation_space_info
    return jsonify(info = info)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/json.py", line 266, in jsonify
    (dumps(data, indent=indent, separators=separators), '\n'),
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/json.py", line 126, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "/usr/lib/python2.7/json/__init__.py", line 251, in dumps
    sort_keys=sort_keys, **kw).encode(obj)
  File "/usr/lib/python2.7/json/encoder.py", line 209, in encode
    chunks = list(chunks)
  File "/usr/lib/python2.7/json/encoder.py", line 434, in _iterencode
    for chunk in _iterencode_dict(o, _current_indent_level):
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 408, in _iterencode_dict
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 332, in _iterencode_list
    for chunk in chunks:
  File "/usr/lib/python2.7/json/encoder.py", line 442, in _iterencode
    o = _default(o)
  File "/home/rigas/.local/lib/python2.7/site-packages/flask/json.py", line 83, in default
    return _json.JSONEncoder.default(self, o)
  File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: 4.8000002 is not JSON serializable

Any ideas what problem might be ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions