ooii / pySuez

Get your water consumption data from your Suez account (www.toutsurmoneau.fr)
Apache License 2.0
8 stars 12 forks source link

API call not working anymore since January the 15th 2024 #28

Open Kelesis opened 5 months ago

Kelesis commented 5 months ago

@ooii again thanks for your work

toutsurmoneau.fr has just been updated as we can see in the source code :

API calls doesn't work anymore but the fix is simple.

After some testing with Python, we now need to call the API with the hostname returned by the redirection when posting credentials, everything else hasn't been changed and works the same way as before.

Indeed calling the API with the base URI before redirection doesn't work anymore.

Here is the code fragment that works :

// getting token works the same way as before // except we need to handle unicode_escape token = regexresult.encode().decode('unicode_escape')

// posting credentials also works the same way as before response = session.post( url, data=data, cookies=response.cookies, allow_redirects=True, timeout=None )

// now we must get the hostname we've been redirected to hostname = re.match('https?://([^/]+)/',response.url).group(1)

// and then call the API with this hostname (And not by using BASE_URI constant) url = "https://" + hostname + API_ENDPOINT_DATA url += '{}/{}/{}'.format( yesterday_year, yesterday_month, counter_id) response = session.get( url )

// Also, there's no need to extract eZSESSID and pass "Cookie" http header anymore, since cookies are kept between 2 session calls and the protocol directly use them. It still works if anyway if we continue to pass this header but all this code can safely be removed.

benbox69 commented 3 months ago

Made a fork and a pull request with your update. I hope that it will be merged soon as I am using another librairy based on this one.