deepgram.errors.DeepgramApiError:违反协议 (_ssl.c:2427) 发生 <urlopen 错误 EOF>

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

提问人:dave 提问时间:11/15/2023 更新时间:11/15/2023 访问量:26

问:

我在 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-3.11

评论

0赞 Steffen Ullrich 11/15/2023
这可能不是程序中的错误,而是某些安全软件由于负载问题、速率限制或类似问题而中断连接或服务器关闭连接。

答:

0赞 Jaswir 12/20/2023 #1

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

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