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

Python 3.5: TypeError, "is not JSON serializable" #43

Closed
pierrelux opened this issue May 2, 2016 · 1 comment
Closed

Python 3.5: TypeError, "is not JSON serializable" #43

pierrelux opened this issue May 2, 2016 · 1 comment
Assignees

Comments

@pierrelux
Copy link

While trying to run examples/agents/random_agent.py from 7b91967 with Python 3.5.1, I get:

Traceback (most recent call last):
  File "examples/agents/random_agent.py", line 36, in <module>
    ob = env.reset()
  File "/home/pierre-luc/anaconda3/lib/python3.5/site-packages/gym-0.0.7-py3.5.egg/gym/core.py", line 96, in reset
    self.monitor._after_reset(observation)
  File "/home/pierre-luc/anaconda3/lib/python3.5/site-packages/gym-0.0.7-py3.5.egg/gym/monitoring/monitor.py", line 228, in _after_reset
    self._close_video_recorder()
  File "/home/pierre-luc/anaconda3/lib/python3.5/site-packages/gym-0.0.7-py3.5.egg/gym/monitoring/monitor.py", line 243, in _close_video_recorder
    self.video_recorder.close()
  File "/home/pierre-luc/anaconda3/lib/python3.5/site-packages/gym-0.0.7-py3.5.egg/gym/monitoring/video_recorder.py", line 144, in close
    self.write_metadata()
  File "/home/pierre-luc/anaconda3/lib/python3.5/site-packages/gym-0.0.7-py3.5.egg/gym/monitoring/video_recorder.py", line 150, in write_metadata
    json.dump(self.metadata, f)
  File "/home/pierre-luc/anaconda3/lib/python3.5/json/__init__.py", line 178, in dump
    for chunk in iterable:
  File "/home/pierre-luc/anaconda3/lib/python3.5/json/encoder.py", line 429, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/home/pierre-luc/anaconda3/lib/python3.5/json/encoder.py", line 403, in _iterencode_dict
    yield from chunks
  File "/home/pierre-luc/anaconda3/lib/python3.5/json/encoder.py", line 403, in _iterencode_dict
    yield from chunks
  File "/home/pierre-luc/anaconda3/lib/python3.5/json/encoder.py", line 436, in _iterencode
    o = _default(o)
  File "/home/pierre-luc/anaconda3/lib/python3.5/json/encoder.py", line 180, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'avconv 9.18-6:9.18-0ubuntu0.14.04.1\nlibavutil     52.  3. 0 / 52.  3. 0\nlibavcodec    54. 35. 0 / 54. 35. 0\nlibavformat   54. 20. 4 / 54. 20. 4\nlibavdevice   53.  2. 0 / 53.  2. 0\nlibavfi
lter    3.  3. 0 /  3.  3. 0\nlibavresample  1.  0. 1 /  1.  0. 1\nlibswscale     2.  1. 1 /  2.  1. 1\n' is not JSON serializable

The error is due to the fact that subprocess.check_output on line 257 of gym/monitoring/video_recording.py returns a bytes string but json.dump expects a str type.

I fixed the problem on my system with str() on the output of check_output:

@property
def version_info(self):
    return {'backend':self.backend,'version': str(subprocess.check_output([self.backend, '-version'])),'cmdline':self.cmdline}

There is a probably a better way to fix this problem portably using six.

@gdb
Copy link
Collaborator

gdb commented May 2, 2016

(Thanks, we'll fix it!)

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