custom_auth_table TypeError: a bytes-like object is required, not 'str'

93 views
Skip to first unread message

黄祥

unread,
Jan 6, 2019, 11:54:10 PM1/6/19
to web2py-users
models/db.py
from gluon.dal import InDBMigrator
db
= DAL(configuration.get(configuration_env + '_' + 'db.uri'),
 pool_size
= configuration.get(configuration_env + '_' + 'db.pool_size'),
 migrate_enabled
= configuration.get(configuration_env + '_' + 'db.migrate_enabled'),
 migrate
= configuration.get(configuration_env + '_' + 'db.migrate'),
 fake_migrate
= configuration.get(configuration_env + '_' + 'db.fake_migrate'),
 fake_migrate_all
= configuration.get(configuration_env + '_' + 'db.fake_migrate_all'),
 adapter_args
= dict(migrator = InDBMigrator),
 check_reserved
= ['all'],
 ignore_field_case
= True,
 entity_quoting
= False,
 lazy_tables
= True
 
)

private/appconfig.ini
[dev_db]
uri              
= sqlite://test.sqlite
pool_size        
= 10 ; ignored for sqlite
migrate_enabled  
= true
migrate          
= true
fake_migrate    
= false
fake_migrate_all
= false

models/db_schema_0_auth.py
... cutted ...
auth
.define_tables(username = True, signature = True, migrate = 'test_')
custom_auth_table
= db[auth.settings.table_user_name]
custom_auth_table
._format = '%(first_name)s %(last_name)s'
... cutted ...

result when access web2py app
2.17.2-stable+timestamp.2018.10.06.18.54.02
(Running on Rocket 1.2.6, Python 3.7.2)

Traceback (most recent call last):
 
File "/Users/sugizo/learn/web2py/gluon/restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "/Users/sugizo/learn/web2py/applications/test/models/db_schema_0_auth.py", line 9, in <module>
    custom_auth_table
= db[auth.settings.table_user_name]
 
File "/Users/sugizo/learn/web2py/gluon/packages/dal/pydal/base.py", line 666, in __getitem__
   
return self.__getattr__(str(key))
 
File "/Users/sugizo/learn/web2py/gluon/packages/dal/pydal/base.py", line 672, in __getattr__
   
return self.lazy_define_table(tablename, *fields, **kwargs)
 
File "/Users/sugizo/learn/web2py/gluon/packages/dal/pydal/base.py", line 624, in lazy_define_table
    polymodel
=polymodel)
 
File "/Users/sugizo/learn/web2py/gluon/packages/dal/pydal/adapters/base.py", line 798, in create_table
   
return self.migrator.create_table(*args, **kwargs)
 
File "/Users/sugizo/learn/web2py/gluon/packages/dal/pydal/migrator.py", line 296, in create_table
    sql_fields_old
= pickle.load(tfile)
TypeError: a bytes-like object is required, not 'str'

same code test in python 2.7.15 running well

thx n best regards,
stifan

Paul Ellis

unread,
Mar 2, 2019, 2:13:33 AM3/2/19
to web2py-users



web2py™    Version 2.17.2-stable+timestamp.2018.10.06.11.34.06
Python    Python 3.7.0:

Traceback (most recent call last
):
 
File "C:\web2py\gluon\restricted.py", line 219, in restricted
   
exec(ccode, environment)
 
File "C:/web2py/applications/admin/controllers/default.py", line 2012, in <module>
 
File "C:\web2py\gluon\globals.py", line 421, in <lambda>
   
self._caller = lambda f: f()
 
File "C:/web2py/applications/admin/controllers/default.py", line 1618, in errors
    error
= pickle.load(fullpath_file)
 
File "C:\web2py\gluon\html.py", line 668, in XML_unpickle
   
return XML(marshal.loads(data))
TypeError: a bytes-like object is required, not 'str'

Me too. I am getting this from an Ajax callback. But it seems to be pickle related.

Paul Ellis

unread,
Mar 2, 2019, 2:34:03 AM3/2/19
to web2py-users
I have solved this by deleting errors. I think there was some errors pickled while running Python 2 still in the directory.

Is it possible your /databases/*.table files were pickled while running under Python 2?

Might need to export the data and start a fresh database with python 3 and then import the data.
Reply all
Reply to author
Forward
0 new messages