stalker python library throws an error for db.session -


i'm trying use stalker production company , seem not able go through file.

http://pythonhosted.org/stalker/tutorial.html

when i'm trying command:

db.session.add(myuser)  

it threw error:

traceback (most recent call last):   file "<pyshell#50>", line 1, in <module>     db.session.add() attributeerror: 'module' object has no attribute 'add' 

i'm relatively new python. can tell me what's wrong in simple terms? thank

use db.dbsession instead of db.session.

the tutorial you're linking outdated. stalker @ version 0.2.6, while api tutorial you're following 0.2.1.

the below code works, same 1 on tutorial save last part.

from stalker import db, user, department  db.setup({"sqlalchemy.url":"sqlite:////home/nanashi/documents/python 2.7/stalker.db"})  myuser = user(     name = "nanashi",     login = "nanashi",     email  = "no@name.com",     password = "none",     description = "i have no name."     )  clan = department(     name = "ola",     description = "we ola you."     )  clan.members.append(myuser)  db.dbsession.add(myuser) db.dbsession.add(clan) db.dbsession.commit() 

result after running:

debug:stalker.db:settings: {'sqlalchemy.url': 'sqlite:////home/nanashi/documents/python 2.7/stalker.db'} debug:stalker.db:engine: engine(sqlite:////home/nanashi/documents/python 2.7/stalker.db) debug:stalker.db:creating tables debug:stalker.models.auth:name out: nanashi [finished in 0.9s] 

this should work fine now. additional tip, best check modules in case don't work. example, exploring stalkers folder , checking out sessions.py file there reveals following code:

from sqlalchemy.orm import (     scoped_session,     sessionmaker, )  # sqlalchemy session manager dbsession = scoped_session(     sessionmaker(         extension=none     ) ) 

that's entirety of code. you've noticed, there's comment there # sqlalchemy session manager above dbsession, massive hint happened db.session.

hope helps.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -