bain3/pronotepy

qrcode missing uuid

Closed this issue · 13 comments

Hi,

I just tried to use the qrcode login method for the 1st time....and got this error....any idea what to do?

client = pronotepy.Client.qrcode_login({"jeton":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx63ED61E2FD6BBFCE8C32E996FEAA416873D69CAEE529855EC76CD56A70EBAA64AA94B0240667C3BF02D9B6E","login":"xxxxxxxxxxxxxx","url":"https://xxxxxxxxx.index-education.net/pronote/mobile.eleve.html"},
TypeError: ClientBase.qrcode_login() missing 1 required positional argument: 'uuid'
bain3 commented

Client.qrcode_login takes 3 agruments. QR code contents, pin to the QR code, and a uuid, which is a (preferably random) string that identifies your application, you can set it to anything you want.

That worked perfectly, suggest to update the instruction then ... or am I blind (I do receive such comments :) )
https://github.com/bain3/pronotepy#qr-code

People may ask how to get that stuff...this is how I did it (there are other methods)
Use google app with "Google Lens", scan the code and copy the content into the client connection line

sorry but this discussion streches a bit further
I now notice that the QR code has a lifetime of 10 mins, i.e. using the documented method only works 'once' and a new code is needed. For the pronote app (using the qr code) things get stored to prevent to re-new the qrcode. Have you already found out what needs to be stored and how it can be re-used with new logins via the py scripts?
As you already know... I have some knowledge to hack/copy/etc... but am no dev/specialist

forget it.... I should just RTFM....sorry

Nope, sorry, back again
I used the python3 -m pronotepy.create_login to create the token and at first the script worked, I could extract all data but less than 10 minutes later this no longer worked.

Traceback (most recent call last):
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronotepy/pronoteAPI.py", line 330, in aes_decrypt
    return Padding.unpad(cipher.decrypt(data), 16)
  File "/home/arjan/.local/lib/python3.10/site-packages/Crypto/Util/Padding.py", line 92, in unpad
    raise ValueError("Padding is incorrect.")
ValueError: Padding is incorrect.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronote_florian_qrcode.py", line 22, in <module>
    client = pronotepy.Client.token_login(
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronotepy/clients.py", line 154, in token_login
    return cls(pronote_url, username, password, mode="token", uuid=uuid)
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronotepy/clients.py", line 390, in __init__
    super().__init__(pronote_url, username, password, ent, mode, uuid)
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronotepy/clients.py", line 104, in __init__
    self.logged_in = self._login()
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronotepy/clients.py", line 207, in _login
    dec = e.aes_decrypt(bytes.fromhex(challenge))
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_old_attempts/pronotepy/pronoteAPI.py", line 332, in aes_decrypt
    raise CryptoError(
pronotepy.exceptions.CryptoError: ('Decryption failed while trying to un pad. (probably bad decryption key/iv)', 'exception happened during login -> probably bad username/password')

note that the pronote-folder contains your latest release

Adding: I do read that pronote generates a new token after eah login but using the initial qrcode json is then also no longer possible so then it seems I would need to generate a new qrcode which then leads to my question; what am I doing wrong ?

bain3 commented

Sorry if the quickstart isn't clear. You should generate your credentials with the create_login script ONCE. Every time you want to log in after that, you should use the Client.token_login. After logging in with the token you must save client[.password, .username, .pronote_url, .uuid] for the next login. client.password changes every login to the next token you must use.

Thanks and I am a bit slow these days.
Would you see this working like this:

  1. manually generate credentials using python3 -m pronotepy.create_login either with qrcode json or user/pwd
  2. output/credentials into a file, e.g. login.txt
  3. use login.txt in the pyscript that runs the actual client, i.e. has client = pronotepy.Client.token_login
  4. that pyscript then updates the login.txt with the new output/credentials (where it actually only needs to update the pwd)
  5. etc.

if you have any running example then I would also be happy to re-use this :)

bain3 commented

Yep, what you described should work. Sorry, I don't currently have an example.

got it working now...
overall it is not that straightforward and I am still not sure if the end-user can manage to get the QR json (I use google lens)
All in all it is a great addition and already saved me twice recently where my ENT went down and this connection kept on working, less dependeices in the chain.
So: great stuff...THANKS

Hi, not sure how to 'sell' this but with a bit of my trial/error and a LOT more from your pre-work....there is now a solution using QRcode

https://github.com/delphiki/hass-pronote