Monday 15 March 2010

python - web2py authentication error in terminal -



python - web2py authentication error in terminal -

i'm new web2py , trying basics down. i'm next instructions in manual (http://web2py.com/books/default/chapter/29/03/overview#adding-authentication)

i downloaded source code web2py, cd web2py direction

`>>>`python web2py.py

brings the screen server port 8000 , password...i come in , start server brings me website expected

i create tab in terminal cd web2py directory. run python

from gluon import * gluon.tools import * db = dal('sqlite://storage.sqlite') auth = auth(db)

my db fine when >>>db._uri or >>>db._dbname when seek auth = auth(db) error:

>>> auth = auth(db) traceback (most recent phone call last): file "<stdin>", line 1, in <module> file "gluon/tools.py", line 1268, in __init__ request = current.request attributeerror: 'thread._local' object has no attribute 'request'

but if dir(auth), seems have imported correctly:

>>> dir(auth) ['_auth__get_migrate', '_http', '__call__', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_get_login_settings', '_get_user_id', '_reset_two_factor_auth', 'accessible_query', 'add_group', 'add_membership', 'add_permission', 'archive', 'basic', 'cas_login', 'cas_validate', 'change_password', 'default_messages', 'default_settings', 'define_signature', 'define_tables', 'del_group', 'del_membership', 'del_permission', 'email_reset_password', 'enable_record_versioning', 'get_or_create_key', 'get_or_create_user', 'get_vars_next', 'groups', 'has_membership', 'has_permission', 'here', 'id_group', 'impersonate', 'is_impersonating', 'is_logged_in', 'log_event', 'login', 'login_bare', 'login_user', 'logout', 'navbar', 'not_authorized', 'profile', 'random_password', 'register', 'register_bare', 'request_reset_password', 'requires', 'requires_login', 'requires_membership', 'requires_permission', 'requires_signature', 'reset_password', 'reset_password_deprecated', 'retrieve_password', 'retrieve_username', 'run_login_onaccept', 'table_cas', 'table_event', 'table_group', 'table_membership', 'table_permission', 'table_user', 'update_groups', 'url', 'user_group', 'user_group_role', 'user_id', 'verify_email', 'wiki', 'wikimenu']

however, noticed version does't have 'db' , friends did might because auth = auth(db) worked

why getting error , how prepare it?

auth requires request object, available (1) within web2py environment created when framework receives http request, or (2) in web2py shell. if in standard python shell or running python script/module outside of web2py environment, there no request object available. in fact, need response, session, , t objects initialize auth.

if working in python shell, best alternative instead open web2py shell:

> python web2py.py -s myapp/mycontroller -m

the above open python shell create web2py environment in context of myapp. -m flag tells run models app well. option, won't need define db or initialize auth because objects available in shell environment (assuming defined in app's models).

if necessary, can run external script in web2py environment using -r flag (see documentation more details).

python osx authentication web2py attributeerror

No comments:

Post a Comment