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 }}
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code. Error message: 401 GET https://storage.googleapis.com/download/storage/v1/b/<redacted file name>/o/secrets?alt=media: ('Request failed with status code', 401, 'Expected one of', <HTTPStatus.OK: 200>, <HTTPStatus.PARTIAL_CONTENT: 206>)
@dylancaponi does it work in the same environment without the _http argument? 401 means unauthorized, so you probably need to "bind the credentials" like the docs say the default does:
If not passed, an _http object is created that is bound to the credentials for the current object
@dylancaponi I don't, but what I would do is keep digging through the source until you find google.auth.transport.requests.AuthorizedSession. You basically want to extract the auth logic they're using and figure out how to combine it with the requests.adapters.HTTPAdapter(max_retries=5) solution, and then pass the resulting session in as _http
Activity
[-]Correct Retry Strategy in Python libraries[/-][+]Add Retry Strategy to manual libraries.[/+]micimize commentedon Jan 21, 2020
This might be possible with the gcs client currently via
Haven't tested though
dylancaponi commentedon Mar 3, 2020
@micimize This is giving me errors (below) on deployment. Any idea why?
I'm assuming Client here is really:
from google.cloud import storagestorage.Client(...)?Code snippet:
Error when attempting
blob.download_as_string():micimize commentedon Mar 3, 2020
@dylancaponi does it work in the same environment without the
_httpargument? 401 means unauthorized, so you probably need to "bind the credentials" like the docs say the default does:micimize commentedon Mar 3, 2020
They broke the monorepo up, but I found where they set credentials for reference:
RunOrVeith commentedon May 13, 2020
Since these retry-able errors happen quite frequently, I'd really like for this to be a feature sooner than later.
Thanks for your efforts!
dylancaponi commentedon Jul 9, 2020
@micimize Yes, the code runs when we don't pass
_http. That is how our normal (non-retrying) connection is established.builtins.storage_client = storage.Client(project='<redacted>')However, that means it's not passing the session that defines 5 retries which I really want to do. Do you know what the proper approach to that is?
micimize commentedon Jul 9, 2020
@dylancaponi I don't, but what I would do is keep digging through the source until you find
google.auth.transport.requests.AuthorizedSession. You basically want to extract the auth logic they're using and figure out how to combine it with therequests.adapters.HTTPAdapter(max_retries=5)solution, and then pass the resulting session in as_httpdylancaponi commentedon Jul 9, 2020
Thanks! I think I want to do something like:
as mentioned here:
googleapis/python-bigquery#59 (comment)
After 8 days of testing, this function did not terminate once due to
connectionResetError!Adding to production code and will report back.
dylancaponi commentedon Jul 21, 2020
We implemented this in production and have seen zero errors after 5 days.
Previously we were seeing ~10 errors a day.
This solved our issues. Thanks @micimize & @pietrodn
in main.py:
Also, remember to only initialize these once outside of your main() function and reuse them in main().
dylancaponi commentedon Dec 4, 2020
The solution above worked for a month or two but we are now experiencing this issue again ...
How is everyone else faring?
andrewsg commentedon Dec 11, 2020
This is now resolved for storage. Retries are supported by default, documentation work for configuring them is pending (for now, see docstrings).
jackkwok commentedon May 17, 2021
@andrewsg : What release version of
google-cloud-storageis retries supported by default?