Handling expired tokens
I believe at some point when you tried to create the client, such that client = coscine.ApiClient(TOKEN)
, using an expired token, you would get an error informing you that the token is expired. I would say this is the expected behavior.
Currently, however, I can create the client without an error and then get a "404 error - The user was not found" when I try to do anything else. For example, project = client.project(PROJECT, toplevel=False)
returns:
{
"name": "RequestRejected",
"message": "Coscine rejected the request sent by the Coscine Python SDK with the following error message: {\"data\":{\"type\":\"https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4\",\"title\":\"Not Found\",\"status\":404,\"detail\":\"The user was not found.\",\"instance\":\"/api/v2/projects?TopLevel=False\\u0026PageSize=50\",\"httpMethod\":\"GET\",\"errorId\":\"UserNotFoundException\"},\"statusCode\":404,\"isSuccess\":false,\"traceId\":\"0HN2VAH16KEE0:00000001\",\"pagination\":null,\"categories\":null}.",
"stack": "---------------------------------------------------------------------------
HTTPError Traceback (most recent call last)
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:423, in ApiClient.send_request(self, request, stream)
422 logger.debug(response.content.decode(\"utf-8\"))
--> 423 response.raise_for_status()
424 return ApiResponse(self, request, response)
File /opt/homebrew/lib/python3.11/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
1020 if http_error_msg:
-> 1021 raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://coscine.rwth-aachen.de/coscine/api/v2/projects?TopLevel=False&PageSize=50
The above exception was the direct cause of the following exception:
RequestRejected Traceback (most recent call last)
Cell In[9], line 1
----> 1 project = client.project(PROJECT, toplevel=False)
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:631, in ApiClient.project(self, key, attribute, toplevel)
603 def project(
604 self,
605 key: str,
606 attribute: property = Project.display_name,
607 toplevel: bool = True
608 ) -> Project:
609 \"\"\"
610 Returns a single Coscine Project via one of its properties.
611
(...)
627 In case the project could not be found via the selected property.
628 \"\"\"
629 results = list(filter(
630 lambda project: project.match(attribute, key),
--> 631 self.projects(toplevel)
632 ))
633 if len(results) > 1:
634 raise TooManyResults(
635 \"Found more than 1 project with a property matching \"
636 f\"the key '{key}'. \"
(...)
639 \"Use a different (unique) property to filter by!\"
640 )
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:596, in ApiClient.projects(self, toplevel)
585 \"\"\"
586 Retrieves a list of all Coscine projects that the creator of
587 the Coscine API token is currently a member of.
(...)
593 Set it to False to include all (sub-)projects in the results.
594 \"\"\"
595 uri = self.uri(\"projects\")
--> 596 response = self.get(uri, params={\"TopLevel\": toplevel})
597 return [
598 Project(self, item)
599 for page in response.pages()
600 for item in page.data
601 ]
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:526, in ApiClient.get(self, *args, **kwargs)
524 kwargs[\"params\"] = {}
525 kwargs[\"params\"][\"PageSize\"] = 50
--> 526 return self.request(\"GET\", *args, **kwargs)
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:463, in ApiClient.request(self, method, stream, *args, **kwargs)
436 \"\"\"
437 Sends a request to the Coscine REST API. This method is used
438 internally. As a user of the ApiClient you should use the methods
(...)
460 See coscine.ApiClient.handle_request_exception
461 \"\"\"
462 request = requests.Request(method, *args, **kwargs)
--> 463 return self.send_request(request, stream)
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:426, in ApiClient.send_request(self, request, stream)
424 return ApiResponse(self, request, response)
425 except requests.exceptions.RequestException as error:
--> 426 self.handle_request_exception(error)
427 raise error
File /opt/homebrew/lib/python3.11/site-packages/coscine/client.py:498, in ApiClient.handle_request_exception(exception)
493 if exception.response.status_code == 401:
494 raise AuthenticationError(
495 \"Invalid Coscine API token! The token was rejected \"
496 \"by Coscine. Check whether it is expired.\"
497 ) from exception
--> 498 raise RequestRejected(
499 \"Coscine rejected the request sent by the Coscine Python SDK \"
500 \"with the following error message: \"
501 f\"{exception.response.content.decode('utf-8')}.\"
502 ) from exception
RequestRejected: Coscine rejected the request sent by the Coscine Python SDK with the following error message: {\"data\":{\"type\":\"https://datatracker.ietf.org/doc/html/rfc7231#section-6.5.4\",\"title\":\"Not Found\",\"status\":404,\"detail\":\"The user was not found.\",\"instance\":\"/api/v2/projects?TopLevel=False\\u0026PageSize=50\",\"httpMethod\":\"GET\",\"errorId\":\"UserNotFoundException\"},\"statusCode\":404,\"isSuccess\":false,\"traceId\":\"0HN2VAH16KEE0:00000001\",\"pagination\":null,\"categories\":null}."
}