Skip to content

Commit a5c2f3e

Browse files
authored
ppai/image-classification: add exponential retries to download file (#6668)
## Description Fixes #6463 Even though the `Connection reset by peer` is a transient error and we can't do much to solve it on our side, we retry the request with exponential backoff and hopefully it'll work at some point. This will hopefully decrease the number of flaky test runs. ## Checklist - [ ] I have followed [Sample Guidelines from AUTHORING_GUIDE.MD](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md) - [ ] README is updated to include [all relevant information](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#readme-file) - [ ] **Tests** pass: `nox -s py-3.6` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] **Lint** pass: `nox -s lint` (see [Test Environment Setup](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/AUTHORING_GUIDE.md#test-environment-setup)) - [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones) - [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones) - [ ] Please **merge** this PR for me once it is approved. - [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/.github/CODEOWNERS) with the codeowners for this sample
1 parent 0501ae4 commit a5c2f3e

File tree

1 file changed

+3
-1
lines changed
  • people-and-planet-ai/image-classification

1 file changed

+3
-1
lines changed

people-and-planet-ai/image-classification/predict.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from google.cloud.aiplatform.gapic.schema import predict
2222
import requests
2323

24+
from train_model import with_retries
25+
2426

2527
def run(
2628
project: str, region: str, model_endpoint_id: str, image_file: str
@@ -43,7 +45,7 @@ def run(
4345
)
4446

4547
base_url = "https://lilablobssc.blob.core.windows.net/wcs-unzipped"
46-
image_bytes = requests.get(f"{base_url}/{image_file}").content
48+
image_bytes = with_retries(lambda: requests.get(f"{base_url}/{image_file}").content)
4749

4850
response = client.predict(
4951
endpoint=client.endpoint_path(

0 commit comments

Comments
 (0)