Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
872 views
in Technique[技术] by (71.8m points)

flask - Mongoengine: TypeError: __init__() got an unexpected keyword argument

I am using flask-mongoengine extension and I have a User class like this:

class User(db.Document, UserMixin):     
    email = db.StringField(max_length=120, required=True, unique=True)
    password_hash = db.StringField(max_length=80, required=True)   
    active = db.BooleanField()
    fb_id = db.StringField(max_length=120, required=False)

    def __init__(self, email, password, fb_id=None, active=True):           
        hashp = md5.md5(password).hexdigest()        
        self.email=email
        self.password_hash=hashp
        self.fb_id=fb_id
        self.active=active

But when I do a simple get: User.objects.get(email = email)

I get the error:

TypeError: __init__() got an unexpected keyword argument 'password_hash'

but I am setting the password_hash in my init though. Surprisingly, if I delete the whole __init__ and pass in everything by args, it works fine.

So I recon I am doing something wrong in the __init__, maybe something due the document super class? I am quite stuck on this, would appreciate your help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try downgrading pymongo.

pip install pymongo==2.8

I was getting this error no matter what and the only way I fixed it was to downgrande pymongo from 3.0 to 2.8.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...