deepgram.errors.DeepgramApiError:<urlopen error EOF occurred in violation of protocol (_ssl.c:2427)>

问题描述 投票:0回答:2

我在 Ubuntu 23.10 64 位上运行 python 3.11.6 和 deepgram api 2.12.0。

我有这个项目的 venv 设置。 我相信这是某种环境问题,但我已将所有软件包更新到当前版本。 非常感谢任何帮助!!

这是我的代码:

from deepgram import Deepgram
import json
DEEPGRAM_API_KEY = 'XXXXX'
PATH_TO_FILE = '/home/dave/Downloads/harvard.wav'
MIMETYPE = 'audio/wav'

def main():
    dg_client = Deepgram(DEEPGRAM_API_KEY)

    with open(PATH_TO_FILE, 'rb') as audio:
    source = {'buffer': audio, 'mimetype': MIMETYPE}
    options = {"smart_format": False, "model": "nova", "language": "en-GB"}
    print('Requesting transcript... for ', PATH_TO_FILE)
    response = dg_client.transcription.sync_prerecorded(source, options)
    print(json.dumps(response, indent=4))

main()

和堆栈跟踪:

Traceback (most recent call last):
  File "/usr/lib/python3.11/urllib/request.py", line 1348, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.11/http/client.py", line 1286, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.11/http/client.py", line 1332, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.11/http/client.py", line 1281, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.11/http/client.py", line 1080, in _send_output
    self.send(chunk)
  File "/usr/lib/python3.11/http/client.py", line 1002, in send
    self.sock.sendall(data)
  File "/usr/lib/python3.11/ssl.py", line 1274, in sendall
    v = self.send(byte_view[count:])
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 1243, in send
    return self._sslobj.write(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2427)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dave/Dropbox/Code/LLM/venv/lib/python3.11/site-packages/deepgram/_utils.py", line 203, in _sync_request
    return attempt()
           ^^^^^^^^^
  File "/home/dave/Dropbox/Code/LLM/venv/lib/python3.11/site-packages/deepgram/_utils.py", line 177, in attempt
    with urllib.request.urlopen(req, timeout=timeout) as resp:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 216, in urlopen
    return opener.open(url, data, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 519, in open
    response = self._open(req, data)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 536, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 496, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 1391, in https_open
    return self.do_open(http.client.HTTPSConnection, req,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/urllib/request.py", line 1351, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error EOF occurred in violation of protocol (_ssl.c:2427)>

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

Traceback (most recent call last):
  File "/home/dave/Dropbox/Code/LLM/Media-Ingest/test.py", line 26, in <module>
    main()
  File "/home/dave/Dropbox/Code/LLM/Media-Ingest/test.py", line 22, in main
    response = dg_client.transcription.sync_prerecorded(source, options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dave/Dropbox/Code/LLM/venv/lib/python3.11/site-packages/deepgram/transcription.py", line 378, in sync_prerecorded
    return SyncPrerecordedTranscription(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dave/Dropbox/Code/LLM/venv/lib/python3.11/site-packages/deepgram/transcription.py", line 121, in __call__
    return _sync_request(
           ^^^^^^^^^^^^^^
  File "/home/dave/Dropbox/Code/LLM/venv/lib/python3.11/site-packages/deepgram/_utils.py", line 209, in _sync_request
    raise DeepgramApiError(exc, http_library_error=exc) from exc
deepgram.errors.DeepgramApiError: <urlopen error EOF occurred in violation of protocol (_ssl.c:2427)>

Process finished with exit code 1

我更新了 venv 中的所有软件包,并与某人验证了代码是正确的。

ssl python-requests python-3.11
2个回答
0
投票

我遇到了同样的问题,用新的 api 密钥替换了它,它又工作了。

我认为此错误意味着您的 api 密钥不再有效,您需要更换它。


0
投票

这是由于 deepgram 请求超时造成的。 我需要使用回调。

© www.soinside.com 2019 - 2024. All rights reserved.