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
{{ message }}
Repository navigation
HttpError error_details isn't populated unless __repr__ is called first #1255
I was trying to handle an HttpError by looking at the contents of the error_details attribute. I noticed the attribute is a null-string unless I trigger the __repr__ function first. For example, this does not work as the error_details is always "". I made a simple test that demonstrates the error:
from googleapiclient import discovery, errors
client = discovery.build(
"discovery", "v1"
)
req = client.apis().getRest(api='fake_api', version='v1')
try:
resp = req.execute()
except errors.HttpError as err:
print(f'Error details are currently: "{err.error_details}"')
print(f'Exception string representation is: "{err}"')
print(f'Error details are currently: "{err.error_details}"')
The output of the above code:
Error details are currently: ""
Exception string representation is: "<HttpError 404 when requesting https://www.googleapis.com/discovery/v1/apis/fake_api/v1/rest?alt=json returned "Requested entity was not found.". Details: "Requested entity was not found.">"
Error details are currently: "Requested entity was not found."
I tested and the behavior is the same on both google-api-python-client-1.12.8 and google-api-python-client-2.0.2
Activity
feat: add status_code property on http error handling (#1185)