Romern / syncMyMoodle

Synchronization client for RWTH Moodle
GNU General Public License v3.0
70 stars 18 forks source link

Can't retrieve session key #112

Closed D-VR closed 3 months ago

D-VR commented 4 months ago

It seems like RWTH Moodle changed how data is stored on the front end, resulting in the following error:

python -m syncmymoodle               
Logging in...
CRITICAL:__main__:Can't retrieve session key

The sessionkey is now stored in a javascript object, and beautiful soup can't find it: M.cfg = {"wwwroot":"https:\/\/moodle.rwth-aachen.de","homeurl":{},"sesskey":"*******","sessiontimeout":"50400","sessiontimeoutwarning":"1200","themerev":"1709792389","slasharguments":1,"theme":"boost_union_rwth","iconsystemmodule":"core\/icon_system_fontawesome","jsrev":"1709792177","admin":"admin","svgicons":true,"usertimezone":"Europa\/Berlin","language":"de","courseId":1,"courseContextId":2,"contextid":1,"contextInstanceId":0,"langrev":1709953813,"templaterev":"1709792177"};var yui1ConfigFn = function(me) {if(/-skin|reset|fonts|grids|base/.test(me.name)){me.type='css';me.path=me.path.replace(/\.js/,'.css');me.path=me.path.replace(/\/yui2-skin/,'/assets/skins/sam/yui2-skin')}};

I've made a pull request which fixes it:

111

One more thing You may need to delete the empty syncm_session cookie in your local directory, since syncmymoodle doesn't act gracefully with invalid cookies leading to exceptions like this:

python -m syncmymoodle               
Logging in...
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/dvr/.local/lib/python3.11/site-packages/syncmymoodle/__main__.py", line 1252, in <module>
    main()
  File "/home/dvr/.local/lib/python3.11/site-packages/syncmymoodle/__main__.py", line 1242, in main
    smm.login()
  File "/home/dvr/.local/lib/python3.11/site-packages/syncmymoodle/__main__.py", line 194, in login
    self.session.cookies.update(pickle.load(f))
                                ^^^^^^^^^^^^^^
EOFError: Ran out of input

might be good to catch those kind of pickle load error and delete the cookie (or give a better error message so the user knows what to do, preventing accidental data loss)

another example of a invalid cookie error (file with a single byte): pickle.UnpicklingError: invalid load key, '\x0a'.