I normally get this error if not connected to internet when using this app locally.
I just ported from web2py to py4web on pythonanywhere an got his error again:
[2022-08-21T17:42:32.169465]: Traceback (most recent call last):
File "/home/www_hest/py4web/py4web/core.py", line 1317, in import_app
module = importlib.machinery.SourceFileLoader(
File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 1034, in load_module
File "<frozen importlib._bootstrap_external>", line 859, in load_module
File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/www_hest/py4web/apps/hest/__init__.py", line 7, in <module>
from .models import db
File "/home/www_hest/py4web/apps/hest/models.py", line 147, in <module>
Field('author', 'reference auth_user', default=get_user(), writable=False, readable=False),
File "/home/www_hest/py4web/apps/hest/models.py", line 128, in get_user
return auth.current_user.get('id') if auth.current_user else None
File "/home/www_hest/py4web/py4web/utils/auth.py", line 493, in current_user
return self.get_user()
File "/home/www_hest/py4web/py4web/utils/auth.py", line 461, in get_user
if not self.session.is_valid():
File "/home/www_hest/py4web/py4web/core.py", line 345, in is_valid
ctx = self.__request_master_ctx__.request_ctx
AttributeError: '_thread._local' object has no attribute 'request_ctx'
[FAILED] loading hest ('_thread._local' object has no attribute 'request_ctx')
In my models.py, I have this function:
def get_user():
return auth.current_user.get('id') if auth.current_user else None