bain3 / pronotepy

A python API wrapper for pronote
MIT License
188 stars 55 forks source link

Error after some period using QR login #308

Closed bdbogjoe closed 2 months ago

bdbogjoe commented 2 months ago

i'm using your great lib to build rest api to access to pronote. : https://github.com/bdbogjoe/pronote-rest

I was able last year to use it with username/password, but now i'm not able to use it any more with ENT auvergne rhone alpes, then i decided to switch to QR login. I'm able to login and get any content. At startup i login with QR info, then keeping the new username/password for next login if i restart the server. But after some time i have one error:

2024-09-17 14:35:28,754 - pronote-rest - ERROR - 'challenge'
2024-09-17 14:35:28,754 - pronote-rest - ERROR - 'challenge'
Traceback (most recent call last):
  File "/home/app/.local/lib/python3.10/site-packages/pronotepy/clients.py", line 859, in post
    return self.communication.post(function_name, post_data)
  File "/home/app/.local/lib/python3.10/site-packages/pronotepy/pronoteAPI.py", line 182, in post
pronotepy.exceptions.PronoteAPIError: Unknown error from pronote: 13 | La page a expiré ! (6)

Traceback (most recent call last):
    rv = self.dispatch_request()
  File "/home/app/.local/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/home/app/app.py", line 182, in homework
  File "/home/app/.local/lib/python3.10/site-packages/pronotepy/clients.py", line 545, in homework
    response = self.post("PageCahierDeTexte", 88, json_data)
    self.refresh()
  File "/home/app/.local/lib/python3.10/site-packages/pronotepy/clients.py", line 341, in refresh
    self._login()
  File "/home/app/.local/lib/python3.10/site-packages/pronotepy/clients.py", line 222, in _login
    challenge = idr["donneesSec"]["donnees"]["challenge"]
KeyError: 'challenge'

I tried to add cron job and login every 5 min, but i have same issue, it looks like the connection expired, and then i cannot use the last password any more. Do you have any suggestion to avoid this "Unknown error from pronote: 13 | La page a expiré !"

bdbogjoe commented 2 months ago

was working fine during more than 4 hours, and then it is crashing

bain3 commented 2 months ago

Hi, yeah fixed. Client refreshes after qrcode_login should now work. The problem is that the client needs to log in again during the refresh, so credentials exported with client.export_credentials() will not work (they are used up by the refresh).

I recommend using client.session_check() which will return True if the client has refreshed. You can then re-export and save the new credentials.

I know this kinda sucks, but that's just how pronote works.

bdbogjoe commented 2 months ago

you are magic, thanks a lot, waiting for release then ;)