MCPcopy
hub / github.com/burnash/gspread / APIError

Class APIError

gspread/exceptions.py:38–70  ·  view source on GitHub ↗

Errors coming from the API itself, such as when we attempt to retrieve things that don't exist.

Source from the content-addressed store, hash-verified

36
37
38class APIError(GSpreadException):
39 """Errors coming from the API itself,
40 such as when we attempt to retrieve things that don't exist."""
41
42 def __init__(self, response: Response):
43 try:
44 error = response.json()["error"]
45 except Exception as e:
46 # in case we failed to parse the error from the API
47 # build an empty error object to notify the caller
48 # and keep the exception raise flow running
49
50 error = {
51 "code": -1,
52 "message": response.text,
53 "status": "invalid JSON: '{}'".format(e),
54 }
55
56 super().__init__(error)
57 self.response: Response = response
58 self.error: Mapping[str, Any] = error
59 self.code: int = self.error["code"]
60
61 def __str__(self) -> str:
62 return "{}: [{}]: {}".format(
63 self.__class__.__name__, self.code, self.error["message"]
64 )
65
66 def __repr__(self) -> str:
67 return self.__str__()
68
69 def __reduce__(self) -> tuple:
70 return self.__class__, (self.response,)
71
72
73class SpreadsheetNotFound(GSpreadException):

Callers 1

requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…