See http://stackoverflow.com/a/26495214/440323.

The problem is not with db access or the DAL but with Auth -- it requires 
the web2py current object (including request, response, session, and T). If 
you really need Auth, you should run your script via the web2py command 
line:

python web2py.py -S myapp -M -R /path/to/script.py

If you just need access to some of the Auth tables, you might consider just 
creating your own definitions of them manually (your definitions only need 
to include tables and fields that you actually need to access, and they 
don't need all the validators, etc. if you won't be doing form input).

Anthony

On Wednesday, October 22, 2014 10:58:59 AM UTC-4, Richard wrote:
>
> Hi,
>
> I want to access an existing database from an outside web2py app script 
> because the database must be input to Orange for data mining.
>
> I tried the following defining but dot not get access top the data:
>
> import os
>
> import sys
>
> import datetime
>
> import calendar
>
> from datetime import date, time
>
> import json
>
> import uuid
>
> sys.path.append("c:\python27\web2py")
>
>
> from gluon.sql import *
>
> from gluon.validators import *
>
>
> module_path = 
> os.path.abspath(os.path.dirname('C:\\web2py\\applications\\wemanops_test\\databases'))
>
> db_name='storage.sqlite'
>
>
> db = DAL('sqlite://storage.sqlite', pool_size=1, folder=module_path, 
> migrate=False, check_reserved=['all'])
>
>
> from gluon.tools import Auth, Crud, Service, PluginManager, prettydate
>
> auth = Auth(db)
>
>
> db.define_table('langu',
>
> Field('langu', 'string'),
>
> format='%(langu)s'
>
> )
>
>
> db.define_table('community',
>
> Field('com_name', 'string', length=15),
>
> Field('address', 'string'),
>
> Field('responsible', 'string'),
>
> Field('latitude', 'string', default=None),
>
> Field('longitude', 'string', default=None),
>
> #User creation can not beadded because mutial dependence of the auth Class
>
> Field('created_date', 'datetime', default=datetime.datetime.now()),
>
> format='%(com_name)s'
>
> )
>
>
> auth.define_tables(username=True, signature=True, migrate=False)
>
>
> print db(db.langu.id>0).select()
>
>
> The error I get is:
>
> Traceback (most recent call last):
>
> File "<console>", line 1, in <module>
>
> File "<string>", line 22, in <module>
>
> File "c:\python27\web2py\gluon\tools.py", line 1268, in __init__
>
> request = current.request
>
> AttributeError: 'thread._local' object has no attribute 'request'
>
>
> What is missing? 
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to