JonasJoKuJonas / homeassistant-WebUntis

Custom component to access data from Web Untis in Home Assistant
https://community.home-assistant.io/t/webuntis-timetable-in-ha/568273
MIT License
52 stars 12 forks source link

Bad Credentials due to username? #89

Closed Chris4712 closed 1 year ago

Chris4712 commented 1 year ago

The problem

I have Home Assistant running with HACS and implemented the WebUntis Integration. Running without problems the last couple of month with two School-Accounts.

Now I installed an update of WebUntis from v0.4.x (don't know the exact version) to 0.6.1 and I am no longer able to receive data for one of the accounts. Both accounts are registered to the same school. Both accounts are able to login via web. But every time I try to add the second account to the HA WebUntis integration it tells me: 'Bad credentials' and 'Code: -8504'

The only difference I can find between the two accounts is the username (and password, of course). While the account that is able to login via HA is written like: 'lisamueller' the other account has a space in its name: 'max mueller'

I already tried to enter the username with single and double quotation marks, but without any positiv result.

Is something like that already known? Could it be a possible reason or any other advice what to do?

Version of Home Assistant?

2023.09.2

What type of installation are you running?

Home Assistant OS

Version of WebUntis

v0.6.1

Last working WebUntis version

v0.4.x

Traceback/Error logs

2023-09-26 21:39:55.343 ERROR (SyncWorker_7) [webuntis] {'jsonrpc': '2.0', 'id': '2023-09-26 21:39:55.173454', 'error': {'message': 'bad credentials', 'code': -8504}} 2023-09-26 21:39:55.949 WARNING (MainThread) [custom_components.webuntis] Login to WebUntis 'school-address@max mueller' failed - OSError: bad credentials

(I changed the login address due to data protection)

Additional information

No response

chrfriese123 commented 1 year ago

Hello,

I'm facing the same issue at the moment. I installed the integration for the first time using HACS (v1.0.0). I also want to setup two accounts. he first one works perfect. For the second one, the login fails. Most likely because the password is "Krauß" with the German ß.

Is there a workaround?

Error logs

2023-10-11 15:03:56.450 DEBUG (MainThread) [webuntis] The URL given doesn't seem to be a valid URL, just gonna prepend "https://"
2023-10-11 15:03:56.452 DEBUG (SyncWorker_3) [webuntis] Making new request:
2023-10-11 15:03:56.452 DEBUG (SyncWorker_3) [webuntis] URL: https://tipo.webuntis.com/WebUntis/jsonrpc.do?school=<xxx>
2023-10-11 15:03:56.989 DEBUG (SyncWorker_3) [webuntis] Valid JSON found
2023-10-11 15:03:56.989 DEBUG (SyncWorker_3) [webuntis]   Got data{"jsonrpc":"2.0","id":"2023-10-11 15:03:56.452412","error":{"message":"bad credentials","code":-8504
2023-10-11 15:03:56.990 ERROR (SyncWorker_3) [webuntis] {'jsonrpc': '2.0', 'id': '2023-10-11 15:03:56.452412', 'error': {'message': 'bad credentials', 'code': -8504}}
chrfriese123 commented 1 year ago

Tried to dig deeper and I used a simple python script to connect to WebUntis with the same credential... and it worked. I can login, read the class list and get timetable of the current day.

import webuntis
import datetime

today = datetime.date.today()
monday = today - datetime.timedelta(days=today.weekday())
friday = monday + datetime.timedelta(days=4)

print(webuntis.__version__)

s = webuntis.Session(
    server='https://tipo.webuntis.com',
    username='7d',
    password='Krauß',
    school='name+city',
    useragent='foo'
)

s.login() 

for klasse in s.klassen():
    print(klasse.name)

source = s.klassen().filter(name='7d')[0]

day = datetime.date.today()

tt = s.timetable(start=day, end=day, klasse=source).to_table()

for time, row in tt:
    print(format(time.strftime('%H:%M')))
    for date, cell in row:
        for period in cell:
            print(', '.join(su.name for su in period.subjects))

s.logout() 

Exactly the same credential don't work with the Home Assistant integration. With additional logging outputs (_LOGGER.info("hc password 1: %s", session.config["password"])), I can confirm that the config information entered was transfered correctly into the session object and is neither altered nor deleted during login trial.

2023-10-11 20:56:45.515 INFO (MainThread) [custom_components.webuntis.config_flow] hc server 1: https://tipo.webuntis.com/WebUntis/jsonrpc.do
2023-10-11 20:56:45.515 INFO (MainThread) [custom_components.webuntis.config_flow] hc school 1: name+city
2023-10-11 20:56:45.515 INFO (MainThread) [custom_components.webuntis.config_flow] hc username 1: 7d
2023-10-11 20:56:45.515 INFO (MainThread) [custom_components.webuntis.config_flow] hc password 1: Krauß

2023-10-11 20:56:45.517 DEBUG (SyncWorker_1) [webuntis] Making new request:
2023-10-11 20:56:45.517 DEBUG (SyncWorker_1) [webuntis] URL: https://tipo.webuntis.com/WebUntis/jsonrpc.do?school=name+city
2023-10-11 20:56:46.057 DEBUG (SyncWorker_1) [webuntis] Valid JSON found
2023-10-11 20:56:46.057 DEBUG (SyncWorker_1) [webuntis]   Got data{"jsonrpc":"2.0","id":"2023-10-11 20:56:45.517114","error":{"message":"bad credentials","code":-8504
2023-10-11 20:56:46.058 ERROR (SyncWorker_1) [webuntis] {'jsonrpc': '2.0', 'id': '2023-10-11 20:56:45.517114', 'error': {'message': 'bad credentials', 'code': -8504}}

2023-10-11 20:56:46.061 INFO (MainThread) [custom_components.webuntis.config_flow] hc server 2: https://tipo.webuntis.com/WebUntis/jsonrpc.do
2023-10-11 20:56:46.061 INFO (MainThread) [custom_components.webuntis.config_flow] hc school 2: name+city
2023-10-11 20:56:46.062 INFO (MainThread) [custom_components.webuntis.config_flow] hc username 2: 7d
2023-10-11 20:56:46.062 INFO (MainThread) [custom_components.webuntis.config_flow] hc password 2: Krauß

The only difference I could spot is that my python-webuntis has version 0.1.22, whereas the home assistant version has 0.1.21. Could this be a root cause?

Anyone has an idea how to continue with the debugging?

JonasJoKuJonas commented 1 year ago

The only difference I could spot is that my python-webuntis has version 0.1.22, whereas the home assistant version has 0.1.21. Could this be a root cause?

I updated the version to 0.1.22. You may check if it will work now.

Chris4712 commented 1 year ago

Installed the update and both logins are accepted now. So, looks fine to me with the current version 1.0.1

Thanks for your effort!

chrfriese123 commented 1 year ago

Hero! My login also works now. Thanks for the fast turn-around.