Looks like you don't have a Python MySQL driver installed on your system. It works in web2py because web2py includes pymysql in /gluon/contrib (but /gluon/contrib is not part of sys.path when running a Python program outside of the web2py context).
Anthony On Tuesday, August 8, 2017 at 9:42:27 PM UTC-4, jim kaubisch wrote: > > I would have thought so, but it fails !!! What am I missing? > > about as basic as can be - > a plain 2-line vanilla python app (with a running mysql db, created with > the same "db = DAL('mysql://root:password@localhost/mfm_curr_lib', > pool_size = 10) " and accessed happily by the web2py app) > > from pydal import DAL, Field > > db = DAL('mysql://root:password@localhost/mfm_curr_lib', pool_size = 10) > > > … produces > > > RuntimeError: 'Failure to connect, tried 5 times:\nTraceback (most recent > call last):\n File "/Library/Python/2.7/site-packages/pydal/base.py", line > 455, in __init__\n self._adapter = adapter(**kwargs)\n File > "/Library/Python/2.7/site-packages/pydal/adapters/__init__.py", line 40, in > __call__\n obj = super(AdapterMeta, cls).__call__(*args, **kwargs)\n File > "/Library/Python/2.7/site-packages/pydal/adapters/base.py", line 373, in > __init__\n super(SQLAdapter, self).__init__(*args, **kwargs)\n File > "/Library/Python/2.7/site-packages/pydal/adapters/base.py", line 50, in > __init__\n self.find_driver()\n File > "/Library/Python/2.7/site-packages/pydal/adapters/base.py", line 101, in > find_driver\n str(self.drivers))\nRuntimeError: No driver of supported ones > (\'MySQLdb\', \'pymysql\', \'mysqlconnector\') is available\n' > > module body in mfm_media_model.py at line 63 > > db = DAL('mysql://root:password@localhost:3306/mfm_curr_lib/', pool_size = > 10) > > function __call__ in base.py at line 170 > > obj = super(MetaDAL, cls).__call__(*args, **kwargs) > > function __init__ in base.py at line 475 > > "Failure to connect, tried %d times:\n%s" % (attempts, tb) > On Tuesday, August 8, 2017 at 6:01:16 PM UTC-7, Anthony wrote: >> >> Sure, you can access the same database from multiple applications (web2py >> or not). >> >> On Tuesday, August 8, 2017 at 6:29:30 PM UTC-4, jim kaubisch wrote: >>> >>> Thanks, I think you're right. But its working now, so I'll revisit it >>> once the delivery heat is off. >>> >>> Please, on the related topic of my other post, I'm I missing something >>> by thinking I should be able to access the SAME mysql db both from web2py >>> as well as a standard Python program, assuming the same version of DAL? >>> In fact, the web2py app creates the db and uses it fine, but the >>> standalone app claims it can't connect to it. >>> >>> I haven't tried it, but what about 2 web2py apps? Can they access the >>> same (mysql) db >>> >>> Thanks >>> >>> On Tuesday, August 8, 2017 at 12:56:23 PM UTC-7, Anthony wrote: >>>> >>>> As I was developing the app, I realized that I was writing basically >>>>> the same code over and over and over, just with slight differences, e.g. >>>>> the table name, the criteria, the fields I wanted to return and their >>>>> display order... >>>>> so a couple of dictionaries to define (1) the tableviews criteria and >>>>> (2) ordered list of fields to return and the core becomes a small >>>>> parameterization of basically the same db query - 10s of lines of code. >>>>> >>>> >>>> Sounds like something you could handle by abstracting everything into a >>>> special function and maybe using Python argument unpacking: >>>> >>>> db(db.table).select(*list_of_fields, **dictonary_of_named_arguments) >>>> >>>> Anthony >>>> >>> -- 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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.