bain3 / pronotepy

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

Educonnect ... does not connect agora06 #150

Closed vingerha closed 2 years ago

vingerha commented 2 years ago

Hi, with the new year ... new stuff too The educonnect has a in-between step which apparently does not work in the generic_functions.

Visual/manual

  1. https://cas.agora06.fr/login?selection=EDU&service=https://0061670h.index-education.net/pronote/eleve.html this opens a page where one has to select parent/legal-rep OR child/level
  2. https://educonnect.education.gouv.fr/idp/profile/SAML2/POST/SSO?execution=e1s1 when clicking on eleve one gets to the logon page
  3. https://educonnect.education.gouv.fr/idp/profile/SAML2/POST/SSO?execution=e1s1

The error comes from the 2nd page so it seems, it tries to put in user/pwd and continue but firts a button needs to be clicked

{"timestamp":1662362876482,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/delegate/redirect/EDU"}

image

Bapt5 commented 2 years ago

We don't click on buttons because we only use requests so no interaction with the web page. I just fixed the problem, it was just that last year Agora didn't use Educonnect and now it use it.

vingerha commented 2 years ago

EDIT: correction on skipping redirect_form... if does NOT skip that but onlu finds one of the 2 required variables, please see below...and missing that, it will not run the session.post section

Noticed you changed the cas_agora06 FYI on the setup, I am running this on my NUC/Ubuntu 22.04 and did not pip install, I have a separate folder for testing, the pronotepy folder is s sub of that. I copied the ent folder ... same/similar issue

generic functions / _cas_edu URL: https://cas.agora06.fr/login?selection=EDU response.text:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
            </head>
    <body onload="document.forms[0].submit()">
        <noscript>
            <p>
                <strong>Note:</strong> Since your browser does not support JavaScript,
                you must press the Continue button once to proceed.
            </p>
        </noscript>

        <form action="https&#x3a;&#x2f;&#x2f;educonnect.education.gouv.fr&#x2f;idp&#x2f;profile&#x2f;SAML2&#x2f;POST&#x2f;SSO" method="post">
            <div>
                <input type="hidden" name="RelayState" value="https&#x3a;&#x2f;&#x2f;cas.agora06.fr&#x2f;saml&#x2f;SAMLAssertionConsumer"/>
                <input type="hidden" name="SAMLRequest" value="VERYLONGSTRINGWITHCHARACTERS="/>

            </div>
            <noscript>
                <div>
                    <input type="submit" value="Continue"/>
                </div>
            </noscript>
        </form>
            </body>
</html>

in redirect_form :

input_SAMLResponse: None
input_relayState: <input name="RelayState" type="hidden" value="https://cas.agora06.fr/saml/SAMLAssertionConsumer"/>

generic functions / _educonnect > URL: https://cas.agora06.fr/delegate/redirect/EDU response.text:

{"timestamp":1662441473877,"status":405,"error":"Method Not Allowed","exception":"org.springframework.web.HttpRequestMethodNotSupportedException","message":"Request method 'POST' not supported","path":"/delegate/redirect/EDU"}
/home/arjan/.local/lib/python3.10/site-packages/bs4/__init__.py:435: MarkupResemblesLocatorWarning: The input looks more like a filename than markup. You may want to open this file and pass the filehandle into Beautiful Soup.
Bapt5 commented 2 years ago

I just fixed the issue

vingerha commented 2 years ago

Better but still not working. I am happy to share a discord session so we can do this online and not send back/forth all this data :) I added some statements in generic_function (see attached) and its output generic_funcTEXT.txt output.txt the final error:

Traceback (most recent call last):
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_2022/pronote_florian_cas2.py", line 20, in <module>
    client = pronotepy.Client('https://0061670h.index-education.net/pronote/eleve.html', username, password, ent)
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_2022/pronotepy/clients.py", line 382, in __init__
    super().__init__(pronote_url, username, password, ent, qr_code)
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_2022/pronotepy/clients.py", line 81, in __init__
    self.attributes, self.func_options = self.communication.initialise()
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_2022/pronotepy/pronoteAPI.py", line 77, in initialise
    self.attributes = self._parse_html(get_response.content)
  File "/mnt/3692670A6ACD9016/docker/homeassistant1/python_scripts/pronote_2022/pronotepy/pronoteAPI.py", line 274, in _parse_html
    raise PronoteAPIError(
pronotepy.exceptions.PronoteAPIError: Page html is different than expected. Be sure that pronote_url is the direct url to your pronote page.
Bapt5 commented 2 years ago

I see the output and everything is going well. Maybe there is a problem with your pronote_url. But there is no problem with the ENT auth.

vingerha commented 2 years ago

Is there a way to share this without posting stuff on a publicly available website?

vingerha commented 2 years ago

If I put both the ent url and pronote url (both from the pronotepy client) together then I can perfectly login via a browser (any browser). On the final error message (row 274 of pronoteAPI) The parsed data it is trying to examine is this one... from my pov it seems that it has not passed the selection parent/elev


<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to your Education Management Software - Authentification</title>
<meta charset="utf-8"/><meta content="IE=edge" http-equiv="X-UA-Compatible"/><meta content="width=device-width, initial-scale=1" name="viewport"/><link href="/content/css/global/kosmos-styleguide-48323e37cc67ac28e95d.css" rel="stylesheet"/><link href="/static/charte-default.css" rel="stylesheet"/><link href="/static/charte.css" rel="stylesheet"/><link href="/static/favicon.ico" rel="icon" type="image/x-icon"/></head>
<body class="cas">
<main>
<header class="color--comp--dark panel text--center cas__header">
<a class="cas__header-link" href="/" title="Return to the authentication service">
<img alt="Skolengo Logo" class="cas__header-logo media-responsive" id="authentification_logo" src="/static/logo.png"/><span class="screen-reader-text">Return to the authentication service</span>
</a>
<span class="cas__header-baseline">
<span class="space space--sm cas__header-spacer"></span>
<span class="h5-like cas__header-baseline-text">Education Management Software</span>
</span>
</header>
<div class="container cas__container">
<div class="row">
<div class="col col--xs-12 col--sm-10 push--sm-1 col--md-8 push--md-2 col--lg-6 push--lg-3 col--xl-4 push--xl-4 cas__col">
<div class="panel panel--outlined cas__panel">
<div class="panel__body">
<h1 class="screen-reader-text cas__wayf-title">S'authentifier en tant que</h1>
<p class="cas__wayf-message">Vous souhaitez vous connecter à votre ENT en tant que :</p>
<form action="/login" class="cas__wayf-form" method="get">
<div>
<div class="cas__wayf-idp h5-like"><span class="space space--sm"></span>
<input class="js-wayf-composant" data-memorisable="true" id="idp-EDU" name="selection" type="radio" value="EDU"/><label class="form__label" for="idp-EDU">Elève ou parent avec votre compte Educonnect</label>
</div>
</div>
<hr class="divider"/><div>
<div class="cas__wayf-idp h5-like"><span class="space space--sm"></span>
<input class="js-wayf-composant" data-memorisable="true" id="idp-AAA" name="selection" type="radio" value="AAA"/><label class="form__label" for="idp-AAA">Personnel de l'Education Nationale avec votre compte Esterel</label>
</div>
</div>
<hr class="divider"/><div>
<div class="cas__wayf-idp h5-like"><span class="space space--sm"></span>
<input class="js-wayf-composant" data-memorisable="true" id="idp-ENT" name="selection" type="radio" value="ENT"/><label class="form__label" for="idp-ENT">Autre compte</label>
</div>
</div>
<hr class="divider slug slug--xs"/><div class="text--right cas__wayf-submit">
<input name="service" type="hidden" value="https://I_REMOVED_THE_PREFIX.index-education.net/pronote/eleve.html"/><input class="btn btn--primary" id="button-submit" name="submit" type="submit" value="Confirm"/></div>
</form>
<script src="/static/wayf.js"></script>
</div>
</div>
</div>
<div class="col col--xs-12 col--sm-10 push--sm-1 col--md-8 push--md-2 col--lg-3 push--lg-0 cas__col"><div class="msg msg--information"><div class="msg__body"><div class="msg__title">EduConnect à la rentrée</div><div class="msg__content">Pour simplifier vos accès aux services numériques, vos identifiants Agora06 ne seront plus valables à compter du 1er septembre.<br/><br/>Pour vous connecter vous aurez besoin de votre <b>compte Educonnect.</b><br/><br/>A la rentrée, un seul choix <b>"Elève ou parent avec votre compte EduConnect"</b><br/>__<br/><br/>Votre établissement va diffuser les informations nécessaires pour aider les parents et les élèves à activer leur compte Educonnect.<br/>__<br/><br/>Plus d'informations <a href="https://www.pedagogie.ac-nice.fr/dane/s-informer/educonnect">en cliquant ici.</a></div></div></div></div><div class="col col--xs-12 col--sm-10 push--sm-1 col--md-8 push--md-2 col--lg-6 push--lg-3 col--xl-4 push--xl-4 cas__col"><ul class="list--inlined cas__partners"><li><img alt="Agora 06" class="media-responsive" src="/static/agora06.png"/></li></ul></div>
</div>
</div>
</main>
</body>
</html>
Bapt5 commented 2 years ago

It has passed the selection parent/elev as evidenced by the logs you sent me. But I think there is a problem with the cookies but I can't solve it because I can't test anything because I don't have a login for your ENT

vingerha commented 2 years ago

again...can we do this separately ? I am ok to share but not via this page... am 'vingerha' on discord

Bapt5 commented 2 years ago

No problem I will send you a mp on Discord. It's vingerha#????, but what are the numbers after ?

vingerha commented 2 years ago

vingerha#3240