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

Type Error: 4.8000002 is not JSON serializable #73

Open
AndreasRigas opened this issue Mar 5, 2019 · 3 comments
Open

Type Error: 4.8000002 is not JSON serializable #73

AndreasRigas opened this issue Mar 5, 2019 · 3 comments

Comments

@AndreasRigas
Copy link

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 ?

@andrewrigas
Copy link

Solved it by re-install the requirements after I install gym Atari.

@MCGPPeters
Copy link

Got the exact same issue while getting the observation space.

pip list output:

asn1crypto (0.24.0)
atari-py (0.1.7)
atomicwrites (1.3.0)
attrs (19.1.0)
box2d-py (2.3.8)
certifi (2019.3.9)
cffi (1.12.2)
chardet (3.0.4)
Click (7.0)
configparser (3.5.0b2)
coverage (4.5.1)
cryptography (2.3)
Cython (0.29.6)
dnspython (1.15.0)
entrypoints (0.2.3.post3)
enum34 (1.1.6)
Flask (0.11.1)
funcsigs (1.0.2)
future (0.17.1)
futures (3.2.0)
glfw (1.7.1)
gym (0.12.0)
idna (2.8)
imageio (2.5.0)
ipaddress (1.0.17)
itsdangerous (1.1.0)
Jinja2 (2.10)
keyring (15.1.0)
keyrings.alt (3.1)
lockfile (0.12.2)
MarkupSafe (1.1.1)
mock (2.0.0)
more-itertools (5.0.0)
nose2 (0.7.4)
numpy (1.16.2)
pathlib2 (2.3.3)
pbr (4.2.0)
Pillow (5.4.1)
pip (9.0.1)
pluggy (0.9.0)
py (1.8.0)
pycparser (2.19)
pycrypto (2.6.1)
pyglet (1.3.2)
PyGObject (3.30.1)
PyOpenGL (3.1.0)
pytest (4.3.1)
pyxdg (0.25)
requests (2.21.0)
scandir (1.10.0)
scipy (1.2.1)
SecretStorage (2.3.1)
setuptools (40.8.0)
six (1.12.0)
urllib3 (1.24.1)
Werkzeug (0.15.1)
wheel (0.30.0)

@andrewrigas
Copy link

You need to install this numpy==1.11.1rc1 version
Also for if is atari game the observation is List[List[(Double,Double,Double)]] and not List[Double]
For rendering attari you have to install gym >= 0.9.5

Change this to your requirments.txt file
Flask==0.11.1
numpy==1.11.1rc1
gym==0.9.5
requests==2.11.0
pytest

and run

pip install -r requirements.txt

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