Audio API endpoint 9/10 connection closed whilst writing to stream

I have been using the dotnet library llmTornado to upload a simple audio 1min 1mb mp3 and it would fail 9/10. I thought it was the library so coded a simple httpclient to perform the task, same issue. Thinking it might be a dotnet weirdness, I tried a simple python requests

python:

import requests
url = "https://api.openai.com/v1/audio/transcriptions"
with open(FILE_PATH, "rb") as f:
    files = {
        "file": (FILE_PATH, f, "audio/wav")
    }
    data = {
        "model": "whisper-1"
    }
    headers = {
        "Authorization": f"Bearer {API_KEY}",
         "Expect": "" # disable 100-continue
    }

    # Disable keep-alive to avoid mid-stream aborts
    session = requests.Session()
    session.headers.update(headers)
    response = session.post(url, files=files, data=data, headers={"Connection": "close"})

print("Status:", response.status_code)
print("Response:", response.text)



yet the issue continues: I’ve tried wav, I’ve tried mp3, I’ve tried reducing file length to 30secs, to 10 seconds. Is just random. One time works, one time doesn’t.

python error:

c:\Python\Python312>python whisper.py
urllib3.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:2406)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Python\Python312\Lib\site-packages\requests\adapters.py", line 667, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "c:\Python\Python312\Lib\site-packages\urllib3\connectionpool.py", line 843, in urlopen
    retries = retries.increment(
              ^^^^^^^^^^^^^^^^^^
  File "c:\Python\Python312\Lib\site-packages\urllib3\util\retry.py", line 519, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/audio/transcriptions (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2406)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Python\Python312\whisper.py", line 22, in <module>
    response = session.post(url, files=files, data=data, headers={"Connection": "close"})
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python\Python312\Lib\site-packages\requests\sessions.py", line 637, in post
    return self.request("POST", url, data=data, json=json, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python\Python312\Lib\site-packages\requests\sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python\Python312\Lib\site-packages\requests\sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Python\Python312\Lib\site-packages\requests\adapters.py", line 698, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.openai.com', port=443): Max retries exceeded with url: /v1/audio/transcriptions (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2406)')))

and the dotnet c#code

        public async Task<string> TranscribeAsync(string apiKey, string filePath, string model = "whisper-1")
        { 
            var handler = new SocketsHttpHandler
            { 
#if MODERN
                RequestVersion = HttpVersion.Version11,
                RequestVersionPolicy = HttpVersionPolicy.RequestVersionOrLower
#endif 
                AutomaticDecompression = DecompressionMethods.All,
                Expect100ContinueTimeout = TimeSpan.FromSeconds(0)
            };

            var _httpClient = new HttpClient(handler, disposeHandler: true);
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey);
            using var form = new MultipartFormDataContent();

            // Buffer the file fully before sending
            var fileBytes = await File.ReadAllBytesAsync(filePath);
            var fileContent = new ByteArrayContent(fileBytes);
            fileContent.Headers.ContentType = new MediaTypeHeaderValue("audio/mpeg");

            form.Add(fileContent, "file", Path.GetFileName(filePath));
            form.Add(new StringContent(model), "model");

            using var response = await _httpClient.PostAsync("https://api.openai.com/v1/audio/transcriptions", form);

            response.EnsureSuccessStatusCode();
            return await response.Content.ReadAsStringAsync();
        }

and error messages without trace

An error occurred while sending the request.  
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.. 
An existing connection was forcibly closed by the remote host. 



So I'm thinking it has to be my machine / network. But I can use chat / responses endpoints fine, upload images, videos (to gemini). Its just the AUDIO endpoint, and as I Say, it works sometimes, 1/5  sometimes 1/10, and then it will work 3 times in a row.

Any ideas, would be appreciated. 

Cheers

turns out was my network / ISP doing “something” that broke the SSL connection something.

curl verbose option gave the clue

curl: (56) schannel: failed to read data from server: SEC_E_MESSAGE_ALTERED (0x8009030F) - The message or signature supplied for verification has been altered

* schannel: remote party requests renegotiation
* schannel: renegotiating SSL/TLS connection


something forcing a renegotiation that then caused it to fail. Strangely only on audio, images were fine. Audio size / length didn’t seem to be a problem. I don’t know. Anything tried a different network and it worked.

Now using cloudflare one.one.one.one free VPN and it is working. :smh:

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.