[Error] Error with edupage.get_timetable.
ltlklr opened this issue · 18 comments
The "Login" example works fine, I get no errors, but when I try to use the "Get the timetable for a date" example I get this error:
File "C:\Users\L-hub\Desktop\Bot\Bot.py", line 7, in <module>
timetable = edupage.get_timetable(today) # returns EduTimetable
File "C:\Program Files\Python36\lib\site-packages\edupage_api\__init__.py", line 118, in get_timetable
subject_name = self.ids.id_to_subject(subject_id)
File "C:\Program Files\Python36\lib\site-packages\edupage_api\utils.py", line 61, in id_to_subject
return self.dbi.get("subjects").get(s_id).get("short")
AttributeError: 'NoneType' object has no attribute 'get'
print(edupage.data.get("dbi") == None)
Returns False.
I'll add better logging to resolve help us resolve this issue, than you can send the log so we can look at what went wrong.
Running print(edupage.data.get("dbi"))
returns alot of (I changed the name and the ID of the teacher to not mention real names and ID's.):
{'teachers': {'-21313452435': {'id': '-21313452435', 'firstname': 'Adfgsdfg', 'lastname': 'sfgdgsdfg', 'short': 'sfgsdfgdsfg', 'gender': 'F', 'classroomid': '', 'datefrom': '', 'dateto': '', 'isOut': False},
Running
print(edupage.data.get("dbi"))
returns alot of (I changed the name and the ID of the teacher to not mention real names and ID's.):
{'teachers': {'-21313452435': {'id': '-21313452435', 'firstname': 'Adfgsdfg', 'lastname': 'sfgdgsdfg', 'short': 'sfgsdfgdsfg', 'gender': 'F', 'classroomid': '', 'datefrom': '', 'dateto': '', 'isOut': False},
print(edupage.data.get("dbi"))
returns teachers, students and subjects.
For getting timetable, use print(edupage.data.get("dp"))
. It should return JSON object in that format:
I do get some information, but its hard to see. How do you get the nice view?
You can put it in a formatter like https://jsonformatter.org/json-pretty-print or use the pprint
library.
print(edupage.data.get("dpi"))
returns None. But print(edupage.data.get("dp"))
returns a JSON. Thanks for the formatter. One more question is there an easy way to translate subjectID to the actual name of the subject?
There's a class IdUtil
that can be created like this:
id_util = IdUtil(edupage.data)
It has a method id_to_subject
.
Don't forget to import it from edupage_api import IdUtil
!
Hello, I've added logging in 0.9.85!
If you edit your code to intialize your edupage object like this:
from edupage_api import LogLevel
edupage = Edupage("subdomain", "username", "password", log_level=LogLevel.DEBUG)
It will print additional debug info. If you could show the console output, we could resolve this issue.
Hi I don't know if ltlklr got the logs for you but I'm having the same problem : so I'll give you mine logs:
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /Users/alexvysokai/PycharmProject/EDUAD/main.py
[DEBUG] Fetched csrf token: 23cd93fae8d070a6c8b7de1543240d103a41eb0c0b2abdfe5b19dd63a6ee41d0bd4a816b +150ms
Traceback (most recent call last):
File "/Users/alexvysokai/PycharmProject/EDUAD/main.py", line 7, in <module>
timetable = edupage.get_timetable(EduDate.today())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/edupage_api/__init__.py", line 169, in get_timetable
classroom_number = self.ids.id_to_classroom(classroom_id[0])
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/edupage_api/utils.py", line 56, in id_to_classroom
return self.dbi.get("classrooms").get(c_id).get("short")
AttributeError: 'NoneType' object has no attribute 'get'
[DEBUG] Parsed html document: {"items":[{"timelineid":"703496","timestamp":"2021 +356ms
[DEBUG] Successfully deseralised data json! +4ms
[DEBUG] Successfully logged in!
[DEBUG] Getting date plans...
[DEBUG] Starting lesson parsing...
[DEBUG] Found dummy lesson!
[DEBUG] Found dummy lesson!
[DEBUG] Parsing subject with id 34168
[DEBUG] Successfully fetched subject name from data!
[DEBUG] Parsing teacher with id ['451273']
[DEBUG] Successfully fetched teacher name from data!
[DEBUG] Parsing classroom number with id ['*2']
Process finished with exit code 1
If it help I am using Pycharm as my IDE.
@Gladosator, it seems, like you are trying to access timetable before login...
Can you please show your code with that error?
I used the example code that on the site. this one :
from edupage_api import Edupage, EduDate, EduTime, LogLevel
edupage = Edupage("Yeah", "Not sharing", "this", log_level=LogLevel.DEBUG)
# Timetable for today
timetable = edupage.get_timetable(EduDate.today())
# Get current time
current_time = EduTime.now()
next_lesson = timetable.get_next_lesson_at_time(current_time)
print(next_lesson)
but I do think I screwed up somewhere because now its giveng me a difrnt log I swear it didn't do that before anyway here you go with the correct log(hopefully) :
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /Users/alexvysokai/PycharmProject/EDUAD/main.py
[DEBUG] Fetched csrf token: 29155b1c856fdd697e2b762aeeadc6259710626f2ff86559571870764dc5530783766576 +156ms
[DEBUG] Parsed html document: {"items":[{"timelineid":"517189","timestamp":"2021 +500ms
[DEBUG] Successfully deseralised data json! +8ms
[DEBUG] Successfully logged in!
[DEBUG] Getting date plans...
[DEBUG] Starting lesson parsing...
[DEBUG] Found dummy lesson!
[DEBUG] Found dummy lesson!
[DEBUG] Parsing subject with id 34168
[DEBUG] Successfully fetched subject name from data!
[DEBUG] Parsing teacher with id ['451273']
[DEBUG] Successfully fetched teacher name from data!
[DEBUG] Parsing classroom number with id ['*2']
Traceback (most recent call last):
File "/Users/alexvysokai/PycharmProject/EDUAD/main.py", line 7, in <module>
timetable = edupage.get_timetable(EduDate.today())
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/edupage_api/__init__.py", line 169, in get_timetable
classroom_number = self.ids.id_to_classroom(classroom_id[0])
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/edupage_api/utils.py", line 56, in id_to_classroom
return self.dbi.get("classrooms").get(c_id).get("short")
AttributeError: 'NoneType' object has no attribute 'get'
Process finished with exit code 1
So, as I said, there's missing a login part. It should be:
...
edupage = Edupage("Subdomain (Name) of your school", "Username or E-Mail", "Password")
edupage.login()
...
Anyway, for code formatting in Markdown are used three backticks (```
) usually followed by abbreviation of programming language (```py
) and also ended by another three backticks (```
)...
Oh, my bad, I didn't realised mistake in the code.
Now I released new version 0.9.86
, which should fix this issue...
Closing this issue, please comment here if you experience it.
Guys I've been trying to get timetable data for long time, and have the same issue. However
Running
print(edupage.data.get("dbi"))
returns alot of (I changed the name and the ID of the teacher to not mention real names and ID's.):
{'teachers': {'-21313452435': {'id': '-21313452435', 'firstname': 'Adfgsdfg', 'lastname': 'sfgdgsdfg', 'short': 'sfgsdfgdsfg', 'gender': 'F', 'classroomid': '', 'datefrom': '', 'dateto': '', 'isOut': False},
print(edupage.data.get("dbi"))
returns teachers, students and subjects. For getting timetable, useprint(edupage.data.get("dp"))
. It should return JSON object in that format:
I have the same issue but print(edupage.data.get("dp"))
is returning empty list, what can be the problem?