memorandum.
The secret key when using EncryptedCookieStorage for aiohttp_session is a 32-byte bytes-like object or it. Must be a base64 encoded string.
$ pip install cryptography
from cryptography.fernet import Fernet
print(Fernet.generate_key().decode())
In aiohttp, set as follows.
(The generated secret key is put in the environment variable SESSION_SECRET
)
from aiohttp import web
from aiohttp_session import session_middleware
from aiohttp_session.cookie_storage import EncryptedCookieStorage
session_storage = EncryptedCookieStorage(os.environ.get('SESSION_SECRET'))
app = web.Application(middlewares=[session_middleware(session_storage)])
Recommended Posts