canvasapi icon indicating copy to clipboard operation
canvasapi copied to clipboard

Error Code 500 when requesting last_login with get_user

Open ryanbackman opened this issue 3 years ago • 1 comments

Describe the bug

When calling Canvas.get_user with the "last_login" included attribute I get a CanvasException of status code 500. This is only for a subset of users, with no pattern I can discern. Some users have a last_login, some do not. Other includes such as uuid do not have the same issue (or at least, I haven't seen it yet).

To Reproduce

Steps to reproduce the behavior:

  1. Make a call to Canvas.get_user with the "last_login" included
  2. Weep when Error returned.

Expected behavior

I expect to get a User object back with last_login as an included variable.

Environment information

Python 3.7.4 (default, Sep 12 2019, 16:02:06) [GCC 6.3.0 20170516] on linux

Name: canvasapi Version: 2.2.0 Summary: API wrapper for the Canvas LMS Home-page: https://github.com/ucfopen/canvasapi Author: University of Central Florida - Center for Distributed Learning Author-email: [email protected] License: MIT License Location: /usr/local/lib/python3.7/site-packages Requires: requests, pytz Required-by: gfu-canvas

Additional context

Logging Debug Output

2021-08-19 17:30:23,945 - canvasapi.requester - INFO - Request: GET https://georgefox.instructure.com/api/v1/users/sis_user_id:1190885
2021-08-19 17:30:23,948 - canvasapi.requester - DEBUG - Headers: {'Authorization': '********'}
2021-08-19 17:30:23,949 - canvasapi.requester - DEBUG - Data: [('include[]', 'last_login')]
2021-08-19 17:30:24,477 - canvasapi.requester - INFO - Response: GET https://georgefox.instructure.com/api/v1/users/sis_user_id:1190885 500
2021-08-19 17:30:24,479 - canvasapi.requester - DEBUG - Headers: {'Date': 'Thu, 19 Aug 2021 17:30:24 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Server': 'Apache', 'X-Session-Id': '3ce72eb88bed8c78c9f8bce71ba33d55', 'X-Request-Context-Id': '7bca7bf4-e41c-4bf2-8320-a01cda7cdf3c', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'X-Rate-Limit-Remaining': '700.0', 'X-Canvas-Meta': 'q=907;at=171210000000000167;dk=170000000000016;a=1;g=f727kRbtUHdTgc2G045HuWmh8nRfmn17JLCMlu35;s=17121;c=cluster304;z=us-west-2b;o=users;n=api_show;b=1503568;m=1503568;u=0.07;y=0.00;d=0.02;', 'X-Frame-Options': 'SAMEORIGIN', 'X-Request-Cost': '0.08724027799826217', 'Cache-Control': 'no-cache', 'Strict-Transport-Security': 'max-age=31536000', 'Referrer-Policy': 'no-referrer-when-downgrade', 'X-Permitted-Cross-Domain-Policies': 'none', 'X-XSS-Protection': '1; mode=block', 'X-Canvas-User-Id': '171210000000000189', 'X-Download-Options': 'noopen', 'X-Runtime': '0.434146', 'X-Content-Type-Options': 'nosniff', 'Set-Cookie': '_csrf_token=hvzCAXrBOS7W%2F3tLnVsnH5Po3bCrKxvFqxJXrDJGQLcqnx0X8PBlH8jsa51cFTsCC6UIw%3D%3D; path=/; secure, log_session_id=3ce72eb88bed8c78c9f8bce71ba33d55; path=/; secure; HttpOnly, _legacy_normandy_session=Usblv0kAphCWiildJ8rHxker8uYQlR4RWYjNiw0eRHEWec2SyzDcYNCVyS2hAWZK3lEQfRvUnHuUGvW2EOStvULQ5Dq0Ej46pVWdCsFeMpmifSwW-Go4ArUyVST9CM-zTSnIw8.RYHMXIIyFSve04zQz3mFY3Hp7II.YR6VMA; path=/; secure; HttpOnly, canvas_session=Usblv0kAphCWiildJ8rHxQlR0eRHEWec2SyzDcYNCVyS2hAWZK3lEQfRvUnHuUGvW2EOStvULQ5Dq0Ej46pVWdCsFeMpmifSwW-Go4ArUyVST9CM-zTSnIw8.RYHMXIIyFSve04zQz3mFY3Hp7II.YR6VMA; path=/; secure; HttpOnly; SameSite=None', 'X-Request-Processor': '053f6253887febb9e', 'X-A11y-Ally': 'Dana Danger Grey', 'Status': '500 Internal Server Error', 'P3P': 'CP="None, see http://www.instructure.com/privacy-policy"'}
2021-08-19 17:30:24,480 - canvasapi.requester - DEBUG - Data: ('{"errors":[{"message":"An error '
 'occurred.","error_code":"internal_server_error"}],"error_report_id":1287}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/gfu_canvas/CanvasUser.py", line 137, in canvas_user
    self._canvas_user = self.rp.canvas.get_user(self.emplid, id_type='sis_user_id', include=['last_login'])
  File "/usr/local/lib/python3.7/site-packages/canvasapi/canvas.py", line 1225, in get_user
    "GET", uri, _kwargs=combine_kwargs(**kwargs)
  File "/usr/local/lib/python3.7/site-packages/canvasapi/requester.py", line 263, in request
    "Encountered an error: status code {}".format(response.status_code)
canvasapi.exceptions.CanvasException: Encountered an error: status code 500

ryanbackman avatar Aug 19 '21 17:08 ryanbackman

Have you tried requesting the users with errors through the live api? Additionally, is it possible some of the users haven't logged in at all, causing errors?

lucas-salas avatar Nov 18 '21 06:11 lucas-salas