#1943 openai.APIConnectionError: Connection error. 开启/关闭代理都报错

2407**6 Posted at: 9 months ago

网络连接失败:Traceback (most recent call last):
File "httpx\_transports\default.py", line 101, in map_httpcore_exceptions
File "httpx\_transports\default.py", line 250, in handle_request
File "httpcore\_sync\connection_pool.py", line 216, in handle_request
File "httpcore\_sync\connection_pool.py", line 196, in handle_request
File "httpcore\_sync\http_proxy.py", line 344, in handle_request
File "httpcore\_sync\http11.py", line 143, in handle_request
File "httpcore\_sync\http11.py", line 93, in handle_request
File "httpcore\_sync\http11.py", line 151, in _send_request_headers
File "contextlib.py", line 153, in exit
File "httpcore\_exceptions.py", line 14, in map_exceptions
httpcore.LocalProtocolError: Illegal header value b'Bearer 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\n'

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

Traceback (most recent call last):
File "openai\_base_client.py", line 982, in request
File "httpx\_client.py", line 914, in send
File "httpx\_client.py", line 942, in _send_handling_auth
File "httpx\_client.py", line 979, in _send_handling_redirects
File "httpx\_client.py", line 1014, in _send_single_request
File "httpx\_transports\default.py", line 249, in handle_request
File "contextlib.py", line 153, in exit
File "httpx\_transports\default.py", line 118, in map_httpcore_exceptions
httpx.LocalProtocolError: Illegal header value b'Bearer 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\n'

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

Traceback (most recent call last):
File "videotrans\util\TestSrtTrans.py", line 19, in run
File "videotrans\translator\__init__.py", line 921, in run
File "videotrans\translator\_base.py", line 81, in run
File "tenacity\__init__.py", line 480, in call
File "videotrans\translator\_openrouter.py", line 57, in _item_task
File "openai\_utils\_utils.py", line 286, in wrapper
File "openai\resources\chat\completions\completions.py", line 1156, in create
File "openai\_base_client.py", line 1259, in post
File "openai\_base_client.py", line 1014, in request
openai.APIConnectionError: Connection error.


=
system:Windows-10-10.0.26200-SP0
version:v3.89
frozen:True
language:zh
root_dir:D:/program/0-Ai/v3.89

但是v3.8版本开启代理正常。
v3.89版本开启或关闭代理都不行。

1 Replies

#1 DeepSeek reply at 9 months ago

根据错误日志,问题出在 OpenAI API 请求的 Authorization 头部值格式错误。错误信息 Illegal header value b'Bearer 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\n' 表明,您的 API Key 末尾包含了一个换行符 \n,这导致 HTTP 请求头非法。

核心原因与解决方案:
您的 API Key 在粘贴时可能不小心包含了不可见的换行符或空格。请按以下步骤检查和修正:

  1. 清理并重新粘贴 API Key:

    • 在 pyVideoTrans 主界面,点击菜单栏的 工具 -> 设置。
    • 找到您正在使用的 OpenAI 或 OpenRouter 等翻译渠道的设置区域。
    • 完全删除现有的 API Key 输入框中的内容。
    • 在一个纯文本编辑器(如记事本)中重新粘贴您的 API Key,确保它是一行连续的字符,前后没有空格或空行。
    • 从编辑器中复制这行干净的 Key,再粘贴回 pyVideoTrans 的设置框中。
  2. 检查代理设置(如果使用):

    • 如果使用代理,请确保代理地址格式正确,例如 http://127.0.0.1:7890,且代理服务本身运行正常。
  3. 版本差异说明:

    • v3.8 版本正常而 v3.89 版本报错,很可能是因为 v3.89 使用了更新版本的 openai 或 httpx 库,这些库对 HTTP 头部格式的校验更为严格,从而暴露了之前被容忍的 Key 格式问题。

完成上述操作后,再次尝试翻译。如果问题依旧,请提供清理 Key 后的新日志。

Thinking...
Post Your Reply
If you have more than 50 messages, you will no longer receive an automatic reply. Please ask a new question!
Open source and free maintenance is not easy. If this project is helpful to you, please consider making a small donation to help the project continue to maintain and update.

Dondate via ko-fi.com

Related resource