TypeError:ObjectId('5c60bffac36cba2d7424af3b')不可序列化JSON

时间:2019-02-11 03:57:25

标签: python amazon-web-services api amazon-ec2 mean-stack

因此,我整天都在尝试将此python api连接到我的AWS ec2实例上的mongodb。我相信我最终必须将其连接起来,因为我设法获得了包含第一个objectid的错误,但是当我命中端点时,我收到了错误消息,指出它不可序列化。我不明白为什么我要使用从flask导入的jsonify强制转换结果,有人可以帮我吗?

这是我的python应用

from flask import Flask, jsonify, request
from flask_pymongo import PyMongo
from pymongo import MongoClient

app = Flask(__name__)

app.config['MONGO_DBNAME'] = 'dummyDB'
app.config['MONGO_URI'] = 'mongodb://myusername:mypassword@ec2-35-153-130-169.compute-1.amazonaws.com:27017/dummyDB?authSource=admin'
client = MongoClient ('mongodb://myusername:mypassword@ec2-35-153-130-169.compute-1.amazonaws.com:27017/dummyDB?authSource=admin')
db = client['dummyDB']

mongo = PyMongo(app)

@app.route('/jobdata', methods=['GET'])
def get_all_jobdata():
  jobdata = mongo.db.jobdata

  output2 = []

  for q in jobdata.find():
    output2.append({
    '_id' : q['_id'],
    'jobcode' : q['jobcode'],
    'date' : q['date'],
    'mean' : q['mean'],
    'std' : q['std']})

    return jsonify({'result' : output2})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=3000)

这就是我的数据enter image description here

0 个答案:

没有答案