Romern / syncMyMoodle

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

Sometimes login fails #29

Closed autoantwort closed 3 years ago

autoantwort commented 3 years ago

Randomly I get the following output:

ip-074:syncMyMoodle xx$ ./syncMyMoodle.py 
Logging in...
Traceback (most recent call last):
  File "/Users/xx/git_projekte/syncMyMoodle/./syncMyMoodle.py", line 553, in <module>
    smm.get_userid()
  File "/Users/xx/git_projekte/syncMyMoodle/./syncMyMoodle.py", line 164, in get_userid
    self.user_id = resp.json()["userid"]
KeyError: 'userid'
Romern commented 3 years ago

I cannot replicate this, but it should now show the response of the function if the key is not there: https://github.com/Romern/syncMyMoodle/commit/c390992fc11b9c38d2826413613ecacc0b0c17a9

autoantwort commented 3 years ago

Now I sometimes get:

ip-074:syncMyMoodle xx$ ./syncMyMoodle.py 
Logging in...
Error while getting userid and access key: {
    "exception": "moodle_exception",
    "errorcode": "invalidtoken",
    "message": "Ung\u00fcltiges Token - Token wurde nicht gefunden"
}

or while the program is running:

Syncing (VO) Compilerbau...
200
{'exception': 'moodle_exception', 'errorcode': 'invalidtoken', 'message': 'Ungültiges Token - Token wurde nicht gefunden'}
Traceback (most recent call last):
  File "/Users/xx/git_projekte/syncMyMoodle/./syncMyMoodle.py", line 569, in <module>
    smm.sync()
  File "/Users/xx/git_projekte/syncMyMoodle/./syncMyMoodle.py", line 270, in sync
    assignments = self.get_assignment(course_id)
  File "/Users/xx/git_projekte/syncMyMoodle/./syncMyMoodle.py", line 189, in get_assignment
    return resp.json()["courses"][0] if len(resp.json()["courses"])>0 else None
KeyError: 'courses'
Romern commented 3 years ago

Hmm, I hadn't encountered that error. Could you add a print statement after line https://github.com/Romern/syncMyMoodle/blob/c390992fc11b9c38d2826413613ecacc0b0c17a9/syncMyMoodle.py#L118 :

print(base64.b64decode(token_base64d).decode())

and look at the content when the error occurs? DO NOT post the exact contents of it, as it can be used to access your Moodle account.

autoantwort commented 3 years ago

The whole output is:

ip-074:syncMyMoodle xx$ ./syncMyMoodle.py 
Logging in...
11bxxxxxxxxxxxxxxxxxxxxxxxxx50d8:::89xxxxxxxxxxxxxxxxxxxxxxxxxxxx38
Error while getting userid and access key: {
    "exception": "moodle_exception",
    "errorcode": "invalidtoken",
    "message": "Ung\u00fcltiges Token - Token wurde nicht gefunden"
}
autoantwort commented 3 years ago

The printed key does not change if that matters, but sometimes it works and sometimes not, seems strange.

Romern commented 3 years ago

Then it is probably a database inconsistency on the RWTH's end, but its very difficult to know.