After stepping through a debugger for a while, I finally fixed the problem.
The key issue is that I was attempting to use the _id
parameter from the MongoDB collection as the userid. I did not realize that the _id
parameter was an ObjectID
type instead of a string or unicode which I needed.
def find_by_username(username):
try:
data = app.mongo.db.users.find_one_or_404({'username': username})
user = User(unicode(data['_id']), data['username'], data['password'])
return user
except HTTPException:
return None
def find_by_id(userid):
try:
data = app.mongo.db.users.find_one_or_404({'_id': ObjectId(userid)})
user = User(unicode(data['_id']), data['username'], data['password'])
return user
Modifying the two functions appropriately fixed this error.