You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Several courses at my institution have access restricted after the semester. When a course is restricted, my access token doesn't have permission to get course details. This results in an AttributeError when trying to instantiate a Course object.
$ curl -H "Authorization: Bearer <my access token>" "<my institution url>/api/v1/courses" | jq .
[
{
// this course I can access
// the course details are listed here
},
{
// this course I cannot access
"id": 77520000000029520,
"access_restricted_by_date": true
},
...
]
>>> from canvasapi import Canvas
>>> API_URL = "my institution url"
>>> API_KEY = "my access key"
>>> canvas = Canvas(API_URL, API_KEY)
>>> courses = canvas.get_courses()
>>> for course in courses:
... print(course)
[course 1 name]
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "D:\Repos\unified-deadline\venv\Lib\site-packages\canvasapi\course.py", line 46, in __str__
return "{} {} ({})".format(self.course_code, self.name, self.id)
^^^^^^^^^^^^^^^^
File "D:\Repos\unified-deadline\venv\Lib\site-packages\canvasapi\canvas_object.py", line 14, in __getattribute__
return super(CanvasObject, self).__getattribute__(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Course' object has no attribute 'course_code'
Expected behavior
I think the wrapper should either ignore restricted courses or have a special model for them.
Environment information
Python version: 3.11.2
CanvasAPI version: 3.0.0
The text was updated successfully, but these errors were encountered:
Describe the bug
Several courses at my institution have access restricted after the semester. When a course is restricted, my access token doesn't have permission to get course details. This results in an AttributeError when trying to instantiate a Course object.
Expected behavior
I think the wrapper should either ignore restricted courses or have a special model for them.
Environment information
The text was updated successfully, but these errors were encountered: