I have an error that I cannot resolve. here is the error I get when I authenticate with postman: TypeError: Object of type ObjectId is not JSON serializable // Werkzeug Debugger File "C:\Users\Amoungui\AppData\Local\Programs\Python\Python39\Lib\json\encoder.py", line 179, in default raise TypeError(f'Object of type {o.class.name} ' TypeError: Object of type ObjectId is not JSON serializable
Here is my code, I followed the official documentation, but at this does not work I do not understand. here is the link of the documentation: https://pythonhosted.org/Flask-JWT/
customer.py
from flask import jsonify, make_response
from config.mongoose import db
import bson
class Customer(db.Document):
_id = db.ObjectIdField(default=bson.ObjectId, primary_key=True) #bson.ObjectId
tel = db.StringField()
password = db.StringField()
def to_json(self):
return {
"_id": self._id,
"tel": self.tel,
"password": self.password,
}
def findAll(self):
users = []
for user in self.objects:
users.append(user)
return users
service.py
from Models.Customer import Customer
from werkzeug.security import safe_str_cmp
find_by_username = {u.tel:u for u in Customer.objects}
find_by_id = {u._id: u for u in Customer.objects}
def auth(username, password):
user = find_by_username.get(username, None)
if user and safe_str_cmp(user.password.encode('utf-8'), password.encode('utf-8')):
return user
def identity(payload):
_id = payload['identity']
return find_by_id.get(_id)
thank's for your help