SubtitleEdit/subtitleedit · error · Exception

Free API quota exceeded?

Error message

Free API quota exceeded?

What it means

Thrown by GoogleTranslateV1 when a System.Net.WebException is caught during the free-endpoint GET (not an HTTP error status, which is handled at line 66). This is a transport-level failure: DNS, connection refused, TLS, or a protocol error from a proxy. The original WebException is preserved as the inner exception.

Source

Thrown at src/libuilogic/AutoTranslate/GoogleTranslateV1.cs:71

            try
            {
                var text = input.Replace("\r", string.Empty).Trim();
                var url = $"translate_a/single?client=gtx&sl={sourceLanguageCode}&tl={targetLanguageCode}&dt=t&q={Utilities.UrlEncode(text)}";

                var result = await _httpClient.GetAsync(url, cancellationToken);
                var bytes = await result.Content.ReadAsByteArrayAsync(cancellationToken);
                jsonResultString = Encoding.UTF8.GetString(bytes).Trim();

                if (!result.IsSuccessStatusCode)
                {
                    Error = jsonResultString;
                    SeLogger.Error($"Error in {StaticName}.Translate: " + Error);
                    throw new Exception($"{StaticName} failed with status code {(int)result.StatusCode} ({result.StatusCode}) - free API quota exceeded?" + Environment.NewLine + Environment.NewLine + jsonResultString);
                }
            }
            catch (WebException webException)
            {
                throw new Exception("Free API quota exceeded?", webException);
            }

            var resultList = ConvertJsonObjectToStringLines(jsonResultString);
            return string.Join(Environment.NewLine, resultList);
        }

        public static List<TranslationPair> GetTranslationPairs()
        {
            return new List<TranslationPair>
            {
                new TranslationPair("AFAR", "aa"),
                new TranslationPair("AFRIKAANS", "af"),
                new TranslationPair("ALBANIAN", "sq"),
                new TranslationPair("AMHARIC", "am"),
                new TranslationPair("ARABIC", "ar"),
                new TranslationPair("ARMENIAN", "hy"),
                new TranslationPair("ASSAMESE", "as"),
                new TranslationPair("AYMARA", "ay"),

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Check basic connectivity: ping/curl https://translate.googleapis.com from the same machine.
  2. Inspect the inner WebException status (ConnectFailure, NameResolutionFailure, etc.) for the root cause.
  3. Configure proxy settings in SubtitleEdit if behind a corporate firewall.
  4. Update the .NET runtime / OS TLS stack if the failure is protocol-related.

Example fix

// before
catch (WebException webException)
{
    throw new Exception("Free API quota exceeded?", webException);
}

// after - stop mislabeling transport errors as 'quota exceeded' and surface the real status
catch (WebException webException)
{
    var status = webException.Status;
    if (status == WebExceptionStatus.Success || webException.Response != null)
    {
        throw new Exception("Free API quota exceeded?", webException);
    }
    throw new Exception($"GoogleTranslateV1 network error ({status}) reaching translate.googleapis.com.", webException);
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight connectivity check to translate.googleapis.com
public static async Task<bool> CanReachGoogleFreeAsync(CancellationToken token)
{
    using var c = new HttpClient { Timeout = TimeSpan.FromSeconds(5) };
    try { (await c.GetAsync("https://translate.googleapis.com", token)).EnsureSuccessStatusCode(); return true; }
    catch { return false; }
}

Try / catch

try
{
    return await googleV1.Translate(text, src, tgt, token);
}
catch (Exception ex) when (ex.InnerException is System.Net.WebException we && we.Response == null)
{
    // Transport error, not quota
    throw new InvalidOperationException("Cannot reach translate.googleapis.com - check network/proxy.", ex);
}
catch (Exception ex) when (ex.Message.Contains("quota exceeded"))
{
    // Likely a rate-limit/quota block
    throw new InvalidOperationException("Google free endpoint rate-limited the request.", ex);
}

Prevention

When it happens

Trigger: The try at GoogleTranslateV1.cs:53 wraps the GET; any WebException (not HttpRequestException) escapes and is caught at line 69. Common with older .NET stacks where the underlying WebRequest surfaces transport errors as WebException rather than the newer HttpRequestException.

Common situations: No internet connection; DNS failure for translate.googleapis.com; corporate firewall/proxy blocking the host; TLS handshake failure on an outdated runtime; the gtx endpoint returning an HTML error page that the stack cannot parse as a clean HTTP response.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/6b91ff4e9a9333b1. Report an issue: GitHub.