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

Object of type 'bytes' is not JSON serializable when I try to predict #14

Open
bhatnagardivyanshu opened this issue Jul 24, 2018 · 1 comment

Comments

@bhatnagardivyanshu
Copy link

Traceback (most recent call last):
File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2309, in call
return self.wsgi_app(environ, start_response)
File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/anaconda3/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1816, in full_dispatch_request
return self.finalize_request(rv)
File "/anaconda3/lib/python3.6/site-packages/flask/app.py", line 1831, in finalize_request
response = self.make_response(rv)
File "/anaconda3/lib/python3.6/site-packages/flask_api/app.py", line 60, in make_response
rv = self.response_class(rv, headers=headers, status=status)
File "/anaconda3/lib/python3.6/site-packages/flask_api/response.py", line 20, in init
content = renderer.render(content, media_type, **options)
File "/anaconda3/lib/python3.6/site-packages/flask_api/renderers.py", line 61, in render
return json.dumps(data, cls=JSONEncoder, ensure_ascii=False, indent=indent)
File "/anaconda3/lib/python3.6/json/init.py", line 238, in dumps
**kw).encode(obj)
File "/anaconda3/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/anaconda3/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/anaconda3/lib/python3.6/site-packages/flask/json/init.py", line 81, in default
return _json.JSONEncoder.default(self, o)
File "/anaconda3/lib/python3.6/json/encoder.py", line 180, in default
o.class.name)
TypeError: Object of type 'bytes' is not JSON serializable

@bhatnagardivyanshu
Copy link
Author

Okay, so I managed to resolve this error by add decode_response = true to redis.StrictRedis.from_url function
Here's what I changed

self._r = redis.StrictRedis.from_url(current_app.config['REDIS_URL'])
has been changed to
self._r = redis.StrictRedis.from_url(current_app.config['REDIS_URL'], decode_responses=True)

What I understood from the problem was that redis is sending the response in bytes and it has to be decoded to a relevant form. I am completely new to Redis and Python so please bear with me.

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

1 participant