TypeError: Object of type Assignment is not JSON serializable — в чём может быть ошибка?
Всем привет! :) Я пытаюсь вывести домашнее задание урока с помощью NetSchoolAPI, но выходит вот такая ошибка:
Traceback (most recent call last):
File "C:\Users\79170\Desktop\ProjectTwo\netschool.py", line 34, in <module>
asyncio.run(main())
File "C:\Users\79170\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\79170\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
return future.result()
File "C:\Users\79170\Desktop\ProjectTwo\netschool.py", line 23, in main
attachments = await ns.attachments(assignment)
File "C:\Users\79170\Desktop\ProjectTwo\venv\lib\site-packages\netschoolapi\netschoolapi.py", line 254, in attachments
self._wrapped_client.client.build_request(
File "C:\Users\79170\Desktop\ProjectTwo\venv\lib\site-packages\httpx\_client.py", line 360, in build_request
return Request(
File "C:\Users\79170\Desktop\ProjectTwo\venv\lib\site-packages\httpx\_models.py", line 339, in __init__
headers, stream = encode_request(
File "C:\Users\79170\Desktop\ProjectTwo\venv\lib\site-packages\httpx\_content.py", line 215, in encode_request
return encode_json(json)
File "C:\Users\79170\Desktop\ProjectTwo\venv\lib\site-packages\httpx\_content.py", line 178, in encode_json
body = json_dumps(json).encode("utf-8")
File "C:\Users\79170\AppData\Local\Programs\Python\Python310\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Users\79170\AppData\Local\Programs\Python\Python310\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\79170\AppData\Local\Programs\Python\Python310\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\79170\AppData\Local\Programs\Python\Python310\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Assignment is not JSON serializable
Вот сам код:
import asyncio
from netschoolapi import NetSchoolAPI
async def main():
# Создаём клиент. Через него мы будем обращаться
# к АПИ электронного дневника
ns = NetSchoolAPI('https://net-school.cap.ru/')
# Логинимся в "Сетевой город"
await ns.login(
'', #Логин ученика
'', #Пароль ученика
511, #id Школы
)
diary = await ns.diary()
for day in diary.schedule:
for lesson in day.lessons:
for assignment in lesson.assignments:
attachments = await ns.attachments(assignment)
if attachments:
print(
f"Some attachments found on day {day.day} on "
f"{lesson.subject} homework: {attachments}"
)
await ns.logout()
if __name__ == '__main__':
asyncio.run(main())