quart
quart copied to clipboard
Not working with PyLTI even after 'import quart.flask_patch'
I'm trying to make an app using Quart together with PyLTI.
PyLTI is originally for Flask, so I'm using import quart.flask_patch.
However, the following error happens when I run the app with python main.py.
Could you please give me some advice? I'm not sure where I should ask for help. If here is not appropriate place to ask such kind of questions, please just close the issue. Thank you in advance.
Error
Traceback (most recent call last):
File "/home/xxx/Project/quart+lti/main.py", line 13, in <module>
@lti(request='session')
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/pylti/flask.py", line 188, in wrapper
the_lti = LTI(lti_args, lti_kwargs)
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/pylti/flask.py", line 37, in __init__
LTIBase.__init__(self, lti_args, lti_kwargs)
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/pylti/common.py", line 470, in __init__
self.nickname = self.name
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/pylti/common.py", line 478, in name
if 'lis_person_sourcedid' in self.session:
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/werkzeug/local.py", line 278, in __get__
obj = instance._get_current_object()
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/werkzeug/local.py", line 407, in _get_current_object
return self.__local() # type: ignore
File "/home/xxx/.cache/pypoetry/virtualenvs/quart+lti-rQY8ksPW-py3.10/lib/python3.10/site-packages/quart/globals.py", line 26, in _ctx_lookup
raise RuntimeError(f"Attempt to access {name} outside of a relevant context")
RuntimeError: Attempt to access session outside of a relevant context
main.py
import quart.flask_patch
from pylti.flask import lti
from quart import Quart, redirect, url_for
app = Quart(__name__)
@app.route('/lti', methods=['POST'])
@lti(request='initial')
async def lti(lti):
return redirect(url_for('index'), code=303)
@app.route('/')
@lti(request='session')
async def index(lti):
return 'index'
app.run(host='0.0.0.0')
Does it work if you uninstall Flask from your environment?
@pgjones Thank you for your response!
Flask is neither installed as a direct dependency nor as indirect dependencies. I'm using poetry for virtualenv management, and its lock file does not include Flask:
$ grep -i flask poetry.lock
description = "A Python ASGI web microframework with the same API as Flask"
Only quart and PyLTI are installed:
$ cat pyproject.toml
[tool.poetry]
name = "quart+lti"
version = "0.1.0"
description = ""
authors = []
[tool.poetry.dependencies]
python = "^3.10"
quart = "^0.17.0"
PyLTI = "^0.7.0"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"