binary-husky/gpt_academic · error · ValueError
ssl_certfile must be provided if ssl_keyfile is provided.
Error message
ssl_certfile must be provided if ssl_keyfile is provided.
What it means
After constructing the uvicorn Server with ssl_keyfile and ssl_certfile from config, the code raises ValueError('ssl_certfile must be provided if ssl_keyfile is provided.') when SSL is half-configured. Note the check runs after Server(config) creation — uvicorn itself may already have validated/failed on the same malformed config before this line.
Source
Thrown at shared_utils/fastapi_server.py:292
# --- --- uvicorn.Config --- ---
ssl_keyfile = None if SSL_KEYFILE == "" else SSL_KEYFILE
ssl_certfile = None if SSL_CERTFILE == "" else SSL_CERTFILE
server_name = "0.0.0.0"
config = uvicorn.Config(
fastapi_app,
host=server_name,
port=PORT,
reload=False,
log_level="warning",
ssl_keyfile=ssl_keyfile,
ssl_certfile=ssl_certfile,
)
server = Server(config)
url_host_name = "localhost" if server_name == "0.0.0.0" else server_name
if ssl_keyfile is not None:
if ssl_certfile is None:
raise ValueError(
"ssl_certfile must be provided if ssl_keyfile is provided."
)
path_to_local_server = f"https://{url_host_name}:{PORT}/"
else:
path_to_local_server = f"http://{url_host_name}:{PORT}/"
if CUSTOM_PATH != '/':
path_to_local_server += CUSTOM_PATH.lstrip('/').rstrip('/') + '/'
# --- --- begin --- ---
server.run_in_thread()
# --- --- after server launch --- ---
app_block.server = server
app_block.server_name = server_name
app_block.local_url = path_to_local_server
app_block.protocol = (
"https"
if app_block.local_url.startswith("https") or app_block.is_colab
else "http"View on GitHub (pinned to d6bde0fa54)
Solutions
- Provide ssl_certfile alongside ssl_keyfile (generate a self-signed pair if needed: openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes).
- Or clear both settings to serve plain HTTP.
- Verify both files exist and are readable by the service user.
Example fix
# before ssl_keyfile = "key.pem" ssl_certfile = None # after ssl_keyfile = "key.pem" ssl_certfile = "cert.pem"
Defensive patterns
Strategy: validation
Validate before calling
if (ssl_keyfile is None) != (ssl_certfile is None):
raise ValueError('ssl_keyfile and ssl_certfile must be set together')
if ssl_keyfile:
import os
assert os.path.exists(ssl_keyfile) and os.path.exists(ssl_certfile), 'ssl files missing' Prevention
- Always provision key and certificate as a pair.
- Validate both paths exist before server startup.
- Use a config linter that rejects half-set HTTPS options.
When it happens
Trigger: Setting ssl_keyfile (e.g. via server config/CUSTOM_PATH https options) without a matching ssl_certfile, then launching the fastapi server; HTTPS requires both halves of the key/certificate pair.
Common situations: Configuring HTTPS with only a private key generated (cert creation step skipped); typos in one of the two variable names; copying an example config that filled only one field.
Related errors
- 在线搜索失败,状态码: {response.status_code}\t{response.content.decode
- 用户代理或助理代理未定义
- user_proxy is not defined
- AZURE_CFG_ARRAY中配置的模型必须以azure开头
- 模型覆盖参数 '{model_override}' 指向一个暂不支持的模型,请检查配置文件。
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/69b3ad9c82ef98b7.
Report an issue: GitHub.