Search code examples
pythonmongodbflaskpymongobson

json_utils.dumps is suddenly returning all unicode from flask


I have a flask application running on centos 6.5 that today suddenly starting spitting out mongodb documents as all unicode from a flask response. it appears json_utils.dumps appears to be the culprit.

results = database.db.collection.find({}).sort('dateCreated', DESCENDING)

resp = Response(json_util.dumps(results),
                mimetype='application/json')
return resp

my response object comes back with a just a bunch of unicode. I edited my code just to see if it was something with the query, mongodb, or pymongo and this works fine printing to stdout

results = database.db.collection.find({}).sort('dateCreated', DESCENDING)
for r in results:
    current_app.logger.info(r)

However this

results = database.db.collection.find({}).sort('dateCreated', DESCENDING)
for r in results:
    current_app.logger.info(json_utils.dumps(r))

its back to printing out unicode to stdout

Can anyone help me figure out what has gone wrong with my server and why json_utils might start doing this? I'm not experiencign this on my dev machine hooked up to the same database running the same exact code. I don't recall any updates I've made to this server either. its been running fine until this morning


Solution

  • The issue was with my python wheel that I used on this machine. The wheel I used was built against a machine running a different version of centos and a different kernel version. I loaded up a machine with the correct versions of both that matched my deployment machine, redeployed the wheel and reinstalled the libraries and the issue was resolved.