dmitry-viskov / pylti1.3-flask-example

PyLTI1p3 Flask usage example
MIT License
19 stars 29 forks source link

Issue with Retrieving Cached Data in Flask App using ExtendedFlaskMessageLaunch #24

Open arush3 opened 10 months ago

arush3 commented 10 months ago

I'm working on a Flask application using the pylti1.3-flask-example as a starting point and encountering an issue with retrieving cached data using ExtendedFlaskMessageLaunch.from_cache. The LMS I'm using is Moodle Cloud.

Relevant part of the code where the issue occurs

message_launch = ExtendedFlaskMessageLaunch.from_cache(launch_id, flask_request, tool_conf, launch_data_storage=launch_data_storage)

Here is the error I get in my Server log: 2023-12-14 02:31:58,043: pylti1p3.exception.LtiException: Launch data not found

This line is contained in the /configure//< difficulty >/ endpoint.

Cache Storage does seem to be empty and message_launch cannot be retrieved by any of the endpoints after /launch where it is generated.

Please let me know if you are aware of a solution to this caching issue. Has anyone experienced a similar problem, or could someone provide insights into what might be going wrong?

Thank you in advance!

eharvey71 commented 10 months ago

I can't quite recall but there was a reason I was avoiding ExtendedFlaskMessageLaunch. In my app, I'm using FlaskMessageLaunch only... Example:

@app.route('/launch/', methods=['POST'])
def launch():
    tool_conf = ToolConfJsonFile(get_lti_config_path())
    request = FlaskRequest()
    launch_data_storage = get_launch_data_storage()
    message_launch = FlaskMessageLaunch(
        request,
        tool_conf,
        launch_data_storage=launch_data_storage
    )
    message_launch_data = message_launch.get_launch_data()
arush3 commented 10 months ago

Thanks eharvey71.

I'm still getting a "Launch data not found" error inside the /api/scoreboard/ endpoint: 2023-12-16 15:28:22,937: File "/home/arush3/mysite_example/game/app_example.py", line 237, in scoreboard 2023-12-16 15:28:22,937: message_launch = FlaskMessageLaunch.from_cache(launch_id, flask_request, tool_conf, 2023-12-16 15:28:22,937: 2023-12-16 15:28:22,938: File "/home/arush3/.local/lib/python3.10/site-packages/pylti1p3/message_launch.py", line 297, in from_cache 2023-12-16 15:28:22,938: raise LtiException("Launch data not found")

I now also get "Invalid Nonce" errors most of the time, but after a few refreshes, the app loads without an "Invalid Nonce" error.

2023-12-16 15:24:36,732: File "/home/arush3/.local/lib/python3.10/site-packages/pylti1p3/message_launch.py", line 670, in validate_nonce 2023-12-16 15:24:36,732: raise LtiException("Invalid Nonce")

Please let me know if you've seen a similar issue or are aware of a solution.

Thank you!