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

Häufiger Logeintrag "no right for getTeachers()" #41

Closed cicero200272 closed 1 year ago

cicero200272 commented 1 year ago

The problem

Hallo Jonas,

mein Log ist voll von diesen Zeilen hier:

2023-01-05 20:27:57.907 ERROR (SyncWorker_9) [webuntis] {'jsonrpc': '2.0', 'id': '2023-01-05 20:27:57.868278', 'error': {'message': 'no right for getTeachers()', 'code': -8509}}

Das wurde schon mal als Bug gemeldet und gefixt (#28), besteht aber offensichtlich immer noch...

Version of Home Assistant?

2022.12.3

What type of installation are you running?

Home Assistant Container

Version of WebUntis

0.3.5

Last working WebUntis version

No response

Traceback/Error logs

No response

Additional information

No response

JonasJoKuJonas commented 1 year ago

Ich brauche den Traceback um nachzuvollziehen welcher Teil des Programmes den Fehler bei dir auslöst!

cicero200272 commented 1 year ago

Sorry, da wird kein Traceback ausgegeben (auch nicht, wenn ich webuntis im Logger auf DEBUG stelle). Man sieht aber im Log, welche Stellen den Fehler verursachen:

image

image

cicero200272 commented 1 year ago

Nachtrag: ich habe doch noch ein paar mehr Infos im Log erzeugen können, allerdings kein Traceback:

2023-01-09 15:29:06.570 DEBUG (SyncWorker_9) [webuntis] Making new request: 2023-01-09 15:29:06.570 DEBUG (SyncWorker_9) [webuntis] URL: https://borys.webuntis.com/WebUntis/jsonrpc.do?school=XXXXX 2023-01-09 15:29:06.570 DEBUG (SyncWorker_9) [webuntis] DATA: {'id': '2023-01-09 15:29:06.569968', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-01-09 15:29:06.612 DEBUG (SyncWorker_9) [webuntis] Valid JSON found 2023-01-09 15:29:06.612 ERROR (SyncWorker_9) [webuntis] {'jsonrpc': '2.0', 'id': '2023-01-09 15:29:06.569968', 'error': {'message': 'no right for getTeachers()', 'code': -8509}}

kloemi commented 1 year ago

Vermutlich haben wir keine Rechte um die getTeachers Funktion aufzurufen, wenn ich im init.py die Zeilen 579 - 592 auskommentier erscheint der Trace nicht mehr. Vielleicht kann man das ja konfigurierbar machen, oder den Zustand speichern, damit die logmessage nicht die Logfiles zuspammt?

    """
    try:
        dic["teachers"] = [
            {"name": str(teacher.name), "long_name": str(teacher.long_name)}
            for teacher in lesson.teachers
        ]
    except:
        pass
    try:
        dic["original_teachers"] = [
            {"name": str(teacher.name), "long_name": str(teacher.long_name)}
            for teacher in lesson.original_teachers
        ]
    except:
        pass
    """
JonasJoKuJonas commented 1 year ago

Ja, der Fehler wird durch ein Rechteproblem hervorgerufen. Ich hatte die letzten Wochen keine Zeit deshalb antworte ich erst jetzt. Kannst du mal bei dir die Auskommentierten Zeilen durch folgendes ersetze und dann die entstehenden Logs schicken:

try:
    lesson.teachers[0].name
    lesson.teachers[0].long_name

    lesson.original_teachers[0].name
    lesson.original_teachers[0].long_name
except IndexError:
    pass # Wenn kein Lehrer für die Stunde eingetragen ist, wird der Fehler abgefangen

Dann kann ich den Bug patchen

kloemi commented 1 year ago

Hi Jonas,

anbei die Traces, hab mal alles auf debug reingepackt, ich hoffe es hilft dir

`2023-02-05 12:45:23.121 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration webuntis which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant 2023-02-05 12:46:12.147 DEBUG (MainThread) [custom_components.webuntis] Creating server instance for 'login' (SCHOOL) 2023-02-05 12:46:12.148 DEBUG (MainThread) [webuntis] The URL given doesn't seem to be a valid URL, just gonna prepend "https://" 2023-02-05 12:46:12.149 DEBUG (MainThread) [custom_components.webuntis] logging in 2023-02-05 12:46:12.151 DEBUG (SyncWorker_1) [webuntis] Making new request: 2023-02-05 12:46:12.151 DEBUG (SyncWorker_1) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:12.393 DEBUG (SyncWorker_1) [webuntis] Valid JSON found 2023-02-05 12:46:12.394 DEBUG (SyncWorker_1) [webuntis] Did get a jsessionid from the server: XXXXXXXXXXXXXXXXXXXX 2023-02-05 12:46:12.443 DEBUG (MainThread) [custom_components.webuntis] Login successful 2023-02-05 12:46:12.443 DEBUG (MainThread) [custom_components.webuntis] updating data 2023-02-05 12:46:12.445 DEBUG (SyncWorker_0) [webuntis] Making new request: 2023-02-05 12:46:12.445 DEBUG (SyncWorker_0) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:12.445 DEBUG (SyncWorker_0) [webuntis] DATA: {'id': '2023-02-05 12:46:12.445235', 'method': 'getSubjects', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:12.537 DEBUG (SyncWorker_0) [webuntis] Valid JSON found 2023-02-05 12:46:13.440 DEBUG (SyncWorker_2) [webuntis] Making new request: 2023-02-05 12:46:13.441 DEBUG (SyncWorker_2) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:13.441 DEBUG (SyncWorker_2) [webuntis] DATA: {'id': '2023-02-05 12:46:13.440751', 'method': 'getPersonId', 'params': {'sn': 'Nachname', 'fn': 'Vorname', 'dob': 0, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:13.485 DEBUG (SyncWorker_2) [webuntis] Valid JSON found 2023-02-05 12:46:13.485 DEBUG (SyncWorker_2) [webuntis] Making new request: 2023-02-05 12:46:13.485 DEBUG (SyncWorker_2) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:13.486 DEBUG (SyncWorker_2) [webuntis] DATA: {'id': '2023-02-05 12:46:13.485810', 'method': 'getTimetable', 'params': {'startDate': 20230205, 'endDate': 20230205, 'id': 3704, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:13.547 DEBUG (SyncWorker_2) [webuntis] Valid JSON found 2023-02-05 12:46:14.311 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:14.312 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:14.312 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:14.311897', 'method': 'getPersonId', 'params': {'sn': 'Nachname', 'fn': 'Vorname', 'dob': 0, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:14.364 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:14.365 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:14.365 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:14.365 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:14.365395', 'method': 'getTimetable', 'params': {'startDate': 20230205, 'endDate': 20230307, 'id': 3704, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:14.547 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:14.634 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:14.634 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:14.634 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:14.634530', 'method': 'getRooms', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:14.722 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:14.724 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:14.724 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:14.724 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:14.724117', 'method': 'getKlassen', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:14.772 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:14.773 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:14.773 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:14.773 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:14.773131', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:14.845 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:14.845 ERROR (SyncWorker_7) [webuntis] {'jsonrpc': '2.0', 'id': '2023-02-05 12:46:14.773131', 'error': {'message': 'no right for getTeachers()', 'code': -8509}} 2023-02-05 12:46:15.008 WARNING (MainThread) [custom_components.webuntis] Updating the propertie next_class of 'SCHOOL@login' failed - OSError: no right for getTeachers() 2023-02-05 12:46:15.011 DEBUG (SyncWorker_2) [webuntis] Making new request: 2023-02-05 12:46:15.011 DEBUG (SyncWorker_2) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.011 DEBUG (SyncWorker_2) [webuntis] DATA: {'id': '2023-02-05 12:46:15.011331', 'method': 'getPersonId', 'params': {'sn': 'Nachname', 'fn': 'Vorname', 'dob': 0, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:15.056 DEBUG (SyncWorker_2) [webuntis] Valid JSON found 2023-02-05 12:46:15.056 DEBUG (SyncWorker_2) [webuntis] Making new request: 2023-02-05 12:46:15.056 DEBUG (SyncWorker_2) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.056 DEBUG (SyncWorker_2) [webuntis] DATA: {'id': '2023-02-05 12:46:15.056559', 'method': 'getTimetable', 'params': {'startDate': 20230205, 'endDate': 20230307, 'id': 3704, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:15.275 DEBUG (SyncWorker_2) [webuntis] Valid JSON found 2023-02-05 12:46:15.629 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:15.630 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.630 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:15.629842', 'method': 'getPersonId', 'params': {'sn': 'Nachname', 'fn': 'Vorname', 'dob': 0, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:15.674 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:15.675 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:15.675 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.675 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:15.675513', 'method': 'getTimetable', 'params': {'startDate': 20230206, 'endDate': 20230206, 'id': 3704, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:15.788 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:15.789 DEBUG (SyncWorker_7) [webuntis] Making new request: 2023-02-05 12:46:15.790 DEBUG (SyncWorker_7) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.790 DEBUG (SyncWorker_7) [webuntis] DATA: {'id': '2023-02-05 12:46:15.789885', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:15.834 DEBUG (SyncWorker_7) [webuntis] Valid JSON found 2023-02-05 12:46:15.834 ERROR (SyncWorker_7) [webuntis] {'jsonrpc': '2.0', 'id': '2023-02-05 12:46:15.789885', 'error': {'message': 'no right for getTeachers()', 'code': -8509}} 2023-02-05 12:46:15.929 WARNING (MainThread) [custom_components.webuntis] Updating the propertie next_day_json of 'SCHOOL@login' failed - OSError: no right for getTeachers() 2023-02-05 12:46:15.932 DEBUG (SyncWorker_5) [webuntis] Making new request: 2023-02-05 12:46:15.932 DEBUG (SyncWorker_5) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.932 DEBUG (SyncWorker_5) [webuntis] DATA: {'id': '2023-02-05 12:46:15.932289', 'method': 'getPersonId', 'params': {'sn': 'Nachname', 'fn': 'Vorname', 'dob': 0, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:15.979 DEBUG (SyncWorker_5) [webuntis] Valid JSON found 2023-02-05 12:46:15.980 DEBUG (SyncWorker_5) [webuntis] Making new request: 2023-02-05 12:46:15.980 DEBUG (SyncWorker_5) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:15.980 DEBUG (SyncWorker_5) [webuntis] DATA: {'id': '2023-02-05 12:46:15.980374', 'method': 'getTimetable', 'params': {'startDate': 20230205, 'endDate': 20230307, 'id': 3704, 'type': 5}, 'jsonrpc': '2.0'} 2023-02-05 12:46:16.181 DEBUG (SyncWorker_5) [webuntis] Valid JSON found 2023-02-05 12:46:16.183 DEBUG (SyncWorker_5) [webuntis] Making new request: 2023-02-05 12:46:16.183 DEBUG (SyncWorker_5) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:16.183 DEBUG (SyncWorker_5) [webuntis] DATA: {'id': '2023-02-05 12:46:16.183588', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:16.235 DEBUG (SyncWorker_5) [webuntis] Valid JSON found 2023-02-05 12:46:16.236 ERROR (SyncWorker_5) [webuntis] {'jsonrpc': '2.0', 'id': '2023-02-05 12:46:16.183588', 'error': {'message': 'no right for getTeachers()', 'code': -8509}} 2023-02-05 12:46:16.240 WARNING (SyncWorker_5) [custom_components.webuntis] Updating of a calendar_event of 'SCHOOL@login' failed - OSError: no right for getTeachers() 2023-02-05 12:46:16.244 DEBUG (SyncWorker_5) [webuntis] Making new request: 2023-02-05 12:46:16.245 DEBUG (SyncWorker_5) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:16.245 DEBUG (SyncWorker_5) [webuntis] DATA: {'id': '2023-02-05 12:46:16.244726', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:16.295 DEBUG (SyncWorker_5) [webuntis] Valid JSON found 2023-02-05 12:46:16.295 ERROR (SyncWorker_5) [webuntis] {'jsonrpc': '2.0', 'id': '2023-02-05 12:46:16.244726', 'error': {'message': 'no right for getTeachers()', 'code': -8509}} 2023-02-05 12:46:16.299 WARNING (SyncWorker_5) [custom_components.webuntis] Updating of a calendar_event of 'SCHOOL@login' failed - OSError: no right for getTeachers() 2023-02-05 12:46:16.303 DEBUG (SyncWorker_5) [webuntis] Making new request: 2023-02-05 12:46:16.303 DEBUG (SyncWorker_5) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:16.303 DEBUG (SyncWorker_5) [webuntis] DATA: {'id': '2023-02-05 12:46:16.303241', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:16.350 DEBUG (SyncWorker_5) [webuntis] Valid JSON found 2023-02-05 12:46:16.350 ERROR (SyncWorker_5) [webuntis] {'jsonrpc': '2.0', 'id': '2023-02-05 12:46:16.303241', 'error': {'message': 'no right for getTeachers()', 'code': -8509}} 2023-02-05 12:46:16.356 WARNING (SyncWorker_5) [custom_components.webuntis] Updating of a calendar_event of 'SCHOOL@login' failed - OSError: no right for getTeachers() 2023-02-05 12:46:16.360 DEBUG (SyncWorker_5) [webuntis] Making new request: 2023-02-05 12:46:16.360 DEBUG (SyncWorker_5) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:16.360 DEBUG (SyncWorker_5) [webuntis] DATA: {'id': '2023-02-05 12:46:16.360381', 'method': 'getTeachers', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:16.412 DEBUG (SyncWorker_5) [webuntis] Valid JSON found 2023-02-05 12:46:16.412 ERROR (SyncWorker_5) [webuntis] {'jsonrpc': '2.0', 'id': '2023-02-05 12:46:16.360381', 'error': {'message': 'no right for getTeachers()', 'code': -8509}} ... ... ... 2023-02-05 12:46:22.921 WARNING (SyncWorker_5) [custom_components.webuntis] Updating of a calendar_event of 'SCHOOL@login' failed - OSError: no right for getTeachers() 2023-02-05 12:46:22.926 DEBUG (SyncWorker_4) [webuntis] Making new request: 2023-02-05 12:46:22.926 DEBUG (SyncWorker_4) [webuntis] URL: https://mese.webuntis.com/WebUntis/jsonrpc.do?school=SCHOOL 2023-02-05 12:46:22.926 DEBUG (SyncWorker_4) [webuntis] DATA: {'id': '2023-02-05 12:46:22.926196', 'method': 'logout', 'params': {}, 'jsonrpc': '2.0'} 2023-02-05 12:46:22.973 DEBUG (SyncWorker_4) [webuntis] Valid JSON found 2023-02-05 12:46:22.976 DEBUG (MainThread) [custom_components.webuntis] Logout successful 2023-02-05 12:46:22.983 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.webuntis

`

JonasJoKuJonas commented 1 year ago

Bekommst du den Fehler auch wenn du den code wie folgend abänderst?

try:
    lesson.teachers[0].name

    lesson.original_teachers[0].name
except IndexError:
    pass # Wenn kein Lehrer für die Stunde eingetragen ist, wird der Fehler abgefangen
kloemi commented 1 year ago

Ja, der trace kommt sobald man den Lehrer abfragt, und man keine Rechte hat. Auch ohne long_name.

kloemi commented 1 year ago

Ich hatte an sowas gedacht:

if self.request_teachers:
            try:
                dic["teachers"] = [
                    {"name": str(teacher.name), "long_name": str(teacher.long_name)}
                    for teacher in lesson.teachers
                ]
            except:
                _LOGGER.warning("Coud not receive teachers - stop requests.")
                self.request_teachers = False
                pass
            try:
                dic["original_teachers"] = [
                    {"name": str(teacher.name), "long_name": str(teacher.long_name)}
                    for teacher in lesson.original_teachers
                ]
            except:
                pass

weiß allerdings nicht ob es nicht auch andere Fälle gibt wo das schief geht, und trotzdem weiterhin request gesendet werden müssen.

JonasJoKuJonas commented 1 year ago

Das problem ist dass die Variable self.request_teachers in den Konfigurationen gespeichert werden muss. Sonst wird sie bei jedem Neustart zurückgesetzt. Das speichern ist aber nicht ganz zu einfach. Da muss ich nochmal etwas herumprobieren.

kloemi commented 1 year ago

OK, ich denke mit einem Logeintrag pro Neustart könnte man leben. Danke für deine Arbeit!

JonasJoKuJonas commented 1 year ago

bug fixed in v0.4.2