platysma / vienna-smartmeter

Python library to access the Wiener Netze Smart Meter private API
MIT License
75 stars 14 forks source link

New Issue: related to Login #178

Open ghhausi opened 4 days ago

ghhausi commented 4 days ago

Login does not work as expected: "Vienna_smartmeter.py" #74: _result = self.session.post( action, data={ "username": self.username, "password": self.password, }, allowredirects=True, ) gets a "200 OK" instead of "302 found" and a Location (with "code=") with the "200 OK" there is no "Location" and therefore no "code=" and Login fails ....

In the post-request there is "&client_data=...." which is shorter in the python function compared to the browser/web-form

Any ideas ?? regards Gerhard

mat-333 commented 4 days ago

I found a solution by replacing the code block from client.py (line 53):

result = self.session.post(
    action,
    data={
        "username": self.username,
        "password": self.password,
    },
    allow_redirects=False,
)

... with the following code. It seems that the authentication was changed. It now requires a two step approach (as found in this issue).

result = self.session.post(
    action,
    data={
        "username": self.username,
        "login": ""
    },
    allow_redirects=False,
)
tree = html.fromstring(result.content)
action = tree.xpath("(//form/@action)")[0]

result = self.session.post(
    action,
    data={
        "username": self.username,
        "password": self.password,
    },
    allow_redirects=False,
)
ghhausi commented 4 days ago

I can confirm: It works! I have a different line number but anyway: Replacing the the section in the beginning of "_login" as described above solves the issue. Thanks for your input!

geros62 commented 3 days ago

Thank you very much, I also tried to resolve this issue but did not have enough time. Now it works again !!!

Thanks!

gsaurer commented 11 hours ago

Thank you, created a PR to get it fixed.