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
When debugging programs that use data from Canvas, it can be extremely valuable to see that data in a handy human-readable format. For example, JSON. This module converts the JSON returned by the Canvas API into objects, but it would be helpful for those objects to return their original JSON strings upon request. Something like a to_json() method in the classes would help.
The text was updated successfully, but these errors were encountered:
Each request in the API returns an object which includes the Requester class so it can make it's own network requests directly, which is why serializing to JSON can be tricky. That said, each class has the CanvasObject parent class which is just a Python object so you can use the dunder methods to get pretty representations of the data. For example:
# set up your Canvas object, etc.course=canvas.get_course(12345)
print(course)
# Course(_requester=<canvasapi.requester.Requester object at 0x106a94d30>, id=12345, name=Some Course, account_id=1, uuid=7W3gvPEhBHI2KbJ02u39kb7PLasfdasd234213096, start_at=None...)# prints a nice representation of the course in the terminalprint(course.__dict__)
# {# '_requester': <canvasapi.requester.Requester at 0x106a94d30>,# 'id': 58866,# 'name': 'Certified Required Training Modules 22-23',# 'account_id': 1,# 'uuid': '7W3gvPEhBHI2KbJ02u39kb7PLsBcl6vySYvxZaD6',# 'start_at': None,# ...# }
For any keys in the class that are also objects, you can print those using the same method:
# get the requester params specifically on an objectprint(course._requester.__dict__)
# { # 'original_url': 'https://myurl.instructure.com', # 'base_url': 'https://myurl.instructure.com/api/v1/',# ...# }
When debugging programs that use data from Canvas, it can be extremely valuable to see that data in a handy human-readable format. For example, JSON. This module converts the JSON returned by the Canvas API into objects, but it would be helpful for those objects to return their original JSON strings upon request. Something like a
to_json()
method in the classes would help.The text was updated successfully, but these errors were encountered: