emmett-framework / emmett

The web framework for inventors
Other
1.04k stars 70 forks source link

Unable to get session and request #293

Closed advh67 closed 3 years ago

advh67 commented 3 years ago

Python 3.8.5 (default, Sep 5 2020, 10:50:12) [GCC 10.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import emmett from emmett import session session Traceback (most recent call last): File "", line 1, in File "/home/advh67/emmett/.venv/lib/python3.8/site-packages/emmett/_internal.py", line 93, in repr obj = self._get_robj() File "/home/advh67/emmett/.venv/lib/python3.8/site-packages/emmett/_internal.py", line 118, in _get_robj return getattr(self.obj.get(), self.name__) AttributeError: 'Context' object has no attribute 'session'

Everything fails to me after updating to 2.1.1 . I am using Arch Linux and Manjaro Linux. Rolling back to 2.0.2 works.

from emmett import request request Traceback (most recent call last): File "", line 1, in File "/home/advh67/emmett/.venv/lib/python3.8/site-packages/emmett/_internal.py", line 93, in repr obj = self._get_robj() File "/home/advh67/emmett/.venv/lib/python3.8/site-packages/emmett/_internal.py", line 118, in _get_robj return getattr(self.obj.get(), self.name__) AttributeError: 'Context' object has no attribute 'request' from emmett import now now <function now at 0x7f08125b2a60> now() DateTime(2020, 10, 30, 8, 49, 41, 505147, tzinfo=Timezone('UTC'))

josejachuf commented 3 years ago

Hi @advh67

works fine for me

Python 3.8.0 (default, Oct 28 2019, 16:14:01) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from emmett import session
>>> 
gi0baro commented 3 years ago

@advh67 can you provide more details about your issue?

Some things that might help debugging:

advh67 commented 3 years ago

This is my own function:


from emmett import session, request, now
def is_logged(self):
        print('-------------')
        print('session=',session)
        print('type of session=',type(session))
        print('session.keys()=',session.keys())
        print("session['auth']=",session['auth'])
        ... (more code)

The result while executing emmett in venv: emmett --app myapp develop --port 7000 The web shows my login screen, I type the user and password, and session accepts a new key 'auth' with all my data.


-------------
session= <sdict {'auth': <sdict {'user': 'advh67, 'data': {'first_name': 'advh67'}, 'last_visit': datetime.datetime(2020, 10, 31, 9, 21, 46, 694484), 'last_dbcheck': datetime.datetime(2020, 10, 31, 9, 21, 46, 694484), 'expiration': 2592000, 'remember': False, 'groups': ['administrator']}>, '_flashes': [('message', 'Bienvenido, advh67')]}>
type of session= <class 'emmett._internal.ContextVarProxy'>
session.keys()= dict_keys(['auth', '_flashes'])
menu pipe failure  ¡¡¡¡---------!!!!!!!!!
on_pipe_failure
pipe failure  ¡¡¡¡---------!!!!!!!!!
/home/adv/emt/.venv/lib/python3.8/site-packages/aiopg/pool.py:308: ResourceWarning: Unclosed 6 connections in <aiopg.pool.Pool object at 0x7f13f6760340>
  warnings.warn(
> ERROR in handlers [/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/asgi/handlers.py:294]:
Application exception:
Traceback (most recent call last):
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/asgi/handlers.py", line 278, in dynamic_handler
    http = await self.router.dispatch()
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/routing/router.py", line 250, in dispatch
    return await match.dispatch(reqargs, current.response)
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/routing/dispatchers.py", line 74, in dispatch
    output = await self.f(**reqargs)
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/pipeline.py", line 328, in flow
    output = await pipe_method(f, **kwargs)
  File "/home/advh67/emt/catalogar/admin_modules/db_async.py", line 309, in pipe
    return await next_pipe(**kwargs)
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/pipeline.py", line 328, in flow
    output = await pipe_method(f, **kwargs)
  File "/home/advh67/emt/catalogar/admin_modules/auth_async.py", line 1890, in pipe
    return await next_pipe(**kwargs)
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/pipeline.py", line 328, in flow
    output = await pipe_method(f, **kwargs)
  File "/home/advh67/emt/catalogar/admin_modules/menu_async.py", line 278, in pipe
    return await next_pipe(**kwargs)
  File "/home/advh67/emt/catalogar/admin_modules/auth_async_controllers.py", line 32, in mylogin
    print('is_logged=',aioauth.is_logged())
  File "/home/advh67/emt/catalogar/admin_modules/auth_async.py", line 1394, in is_logged
    print("session['auth']=",session['auth'])
  File "/home/advh67/emt/.venv/lib/python3.8/site-packages/emmett/_internal.py", line 37, in __getitem__
    return self._get_robj[key]
TypeError: 'method' object is not subscriptable

"session" looks like an sdict object, but python says it is a ContextVarProxy object and cannot access my session data in session['auth']. The production code works well on emmett 2.0.2

I created a clean new virtual environment just for debugging. I used python pip to install emmett.

mkdir emt
cd emt
python -m venv .venv
source .venv/bin/activate
pip install emmett
pip install morepythonmodules
gi0baro commented 3 years ago

@advh67 I'm sorry for the inconvenience, please upgrade to 2.1.2

advh67 commented 3 years ago

Nice :-)

Grazie