Skip to content

Random SSL connection errors when downloading from replicate.delivery on Cloud Run #430

Open
@AusafG5

Description

@AusafG5

I’m using the Replicate Python client to create predictions with webhook callbacks. The webhook sends URLs pointing to images on replicate.delivery CDN. My backend downloads these images asynchronously using aiohttp in a Cloud Run environment.

The problem is, about half the time the downloads fail with this error:

Cannot connect to host replicate.delivery:443 ssl:default [None]

This never happens when I run the same code locally or through ngrok tunnels. I tried messing with SSL settings in aiohttp but no luck.

Here’s the snippet I use to download images:

headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
}

async with aiohttp.ClientSession() as session:
    async with session.get(image_url, headers=headers) as response:
        response.raise_for_status()
        image_data = await response.read()

Some extra info:

I can’t get file objects directly from predictions.get(), only URLs afaik.

I need async downloads because I get multiple webhook calls at once.

Cloud Run’s networking and DNS seem fine otherwise.

Looks like this might be some temporary SSL or network issue with replicate.delivery CDN?

Can you please let me know:

Are there any known connectivity issues with replicate.delivery from cloud platforms like Cloud Run?

Do you recommend any specific SSL or network settings to fix this?

Is there any way to get file-like objects directly from the Replicate API instead of URLs, so I can avoid downloading manually?``

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions