Web2py - Auth with MongoDB -


good day,

i'm trying use mongodb web2py, , started authentication, appeared errors not understand.

in relational database, web2py creates authentication tables, mongodb in collections not created automatically.

below code , error when trying log me:

db.py

db = dal("mongodb://localhost/primer", check_reserved=["mongodb_nonreserved",],  adapter_args={"safe":false}) gluon.tools import auth, service, pluginmanager  auth = auth(db) service = service() plugins = pluginmanager()  auth.settings.remember_me_form = false auth.settings.actions_disabled=['register','change_password','request_reset_password','retrieve_username','profile'] auth.define_tables(username=true)  gluon.contrib.login_methods.ldap_auth import ldap_auth auth.settings.login_methods = [ldap_auth(server='localhost', port='10389', base_dn='ou=people,o=empresa,dc=com,dc=br')] 

the authentication ldap, , works in relational database, has auth_user table.

however, loging using mongodb, appearing following error:

    traceback (most recent call last):   file "c:\users\rafa\desktop\web2py-10-06-2015p4\applications\contrato\controllers/appadmin.py", line 249, in select nrows = db(query, ignore_common_filters=true).count()   file "c:\users\rafa\desktop\web2py-10-06-2015p4\gluon\packages\dal\pydal\objects.py", line 2016, in count return db._adapter.count(self.query,distinct)   file "c:\users\rafa\desktop\web2py-10-06-2015p4\gluon\packages\dal\pydal\adapters\mongo.py", line 200, in count count=true,snapshot=snapshot)['count'])   file "c:\users\rafa\desktop\web2py-10-06-2015p4\gluon\packages\dal\pydal\adapters\mongo.py", line 319, in select sort=mongosort_list, snapshot=snapshot).count()}   file "c:\python27\lib\site-packages\pymongo\collection.py", line 929, in find     return cursor(self, *args, **kwargs) typeerror: __init__() got unexpected keyword argument 'snapshot' 

the database "primer" created , has 2 collections "posts" , "system.indexes"

could me error able use mongodb web2py?

thank you!

found it.

from pymongo's changelog there lot of breaking changes in pymongo 3.0 compared 2.8

the following find/find_one options have been removed:

  • snapshot (use new modifiers option instead)

so uninstall pymongo , try latest before 3.0:

pip install pymongo==2.8.1 

here's attempt:

>>> pydal import * no handlers found logger "web2py" >>> db = dal('mongodb://localhost/connect_test') >>> db.define_table('some',field('key'),field('value')) <table (id,key,value)> >>> db.define_table('some2',field('ref','reference some'),field('value')) <table some2 (id,ref,value)> >>> db(db.some).select() <rows (1)> >>> db(db.some).select().first() <row {'value': 'pir', 'key': 'bla', 'id': 26563964102769618087622556519l}> >>> 

[edit] there's more it. worked @ least pydal 15.03. googling code found following in mongo.py adapter :

        pymongo import version         if 'fake_version' in driver_args:             version = driver_args['fake_version']         if int(version.split('.')[0]) < 3:             raise exception(                 "pydal requires pymongo version >= 3.0, found '%s'"                 % version) 

which soil big frown...

after updating pydal 15.07 apears brake indeed:

runtimeerror: failure connect, tried 5 times: traceback (most recent call last):   file "c:\python27\lib\site-packages\pydal\base.py", line 437, in __init__     self._adapter = adapters[self._dbname](**kwargs)   file "c:\python27\lib\site-packages\pydal\adapters\base.py", line 57, in __call__     obj = super(adaptermeta, cls).__call__(*args, **kwargs)   file "c:\python27\lib\site-packages\pydal\adapters\mongo.py", line 82, in __init__     % version) exception: pydal requires pymongo version >= 3.0, found '2.8.1' 

so it's upgrading pymongo :) pymongo @ 3.0.3 , pydal @ 15.07 works charm again.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -