{"record":{"id":"44fff686a671a894","repo":"binary-husky/gpt_academic","slug":"illegal-custom-path","errorCode":null,"errorMessage":"Illegal custom path","messagePattern":"Illegal custom path","errorType":"validation","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"toolbox.py","lineNumber":708,"sourceCode":"                \"illegal custom path: {}\\npath must not be empty\\ndeploy on root url\".format(\n                    path\n                )\n            )\n            return False\n        if path[0] == \"/\":\n            if path[1] != \"/\":\n                logger.info(\"deploy on sub-path {}\".format(path))\n                return True\n            return False\n        logger.info(\n            \"illegal custom path: {}\\npath should begin with '/'\\ndeploy on root url\".format(\n                path\n            )\n        )\n        return False\n\n    if not is_path_legal(custom_path):\n        raise RuntimeError(\"Illegal custom path\")\n    import uvicorn\n    import gradio as gr\n    from fastapi import FastAPI\n\n    app = FastAPI()\n    if custom_path != \"/\":\n\n        @app.get(\"/\")\n        def read_main():\n            return {\"message\": f\"Gradio is running at: {custom_path}\"}\n\n    app = gr.mount_gradio_app(app, demo, path=custom_path)\n    uvicorn.run(app, host=\"0.0.0.0\", port=port)  # , auth=auth\n\ndef auto_context_clip(current, history, policy='search_optimal'):\n    if policy == 'each_message':\n        return auto_context_clip_each_message(current, history)\n    elif policy == 'search_optimal':","sourceCodeStart":690,"sourceCodeEnd":726,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/toolbox.py#L690-L726","documentation":"Raised by the Gradio launch helper in toolbox.py:708 when the CUSTOM_PATH setting fails the is_path_legal check. is_path_legal only accepts a non-empty string beginning with '/' (with an optional extra '/' segment for sub-paths); anything else — no leading slash, an empty string, a non-string value — logs 'illegal custom path' and returns False, and the caller converts that into RuntimeError('Illegal custom path') before mounting the app.","triggerScenarios":"Setting CUSTOM_PATH = \"gpt-academic\" (missing leading '/'), CUSTOM_PATH = \"\" or leaving it unset in a way that yields an empty string, or CUSTOM_PATH = None / a non-string, then starting the Gradio server which calls this setup path. The check runs before uvicorn.run, so the server never starts.","commonSituations":"Deploying behind a reverse proxy under a sub-path and forgetting the leading slash. Copying a path from a URL bar ('https://host/gpt-academic' instead of '/gpt-academic'). Env-var-driven configs where CUSTOM_PATH comes back as an empty string. Newer revisions where CUSTOM_PATH handling moved, so old .env/config_private.py values no longer validate.","solutions":["Set CUSTOM_PATH to a string starting with '/', e.g. CUSTOM_PATH = \"/gpt-academic\".","If you want root deployment, explicitly set CUSTOM_PATH = \"/\" or remove/empty the override so the default root path is used.","Check config_private.py and environment variables for a CUSTOM_PATH value with whitespace, quotes, or a full URL, and normalize it to a bare absolute path.","Restart the app after fixing the config; the check re-runs at startup."],"exampleFix":"# before (config_private.py)\nCUSTOM_PATH = \"gpt-academic\"  # RuntimeError: Illegal custom path\n\n# after\nCUSTOM_PATH = \"/gpt-academic\"","handlingStrategy":"validation","validationCode":"def normalize_custom_path(p):\n    if p is None:\n        return '/'\n    p = str(p).strip()\n    if not p.startswith('/'):\n        p = '/' + p.lstrip('/')\n    return p or '/'\n\nCUSTOM_PATH = normalize_custom_path(CUSTOM_PATH)\nassert CUSTOM_PATH.startswith('/'), 'custom path must begin with /'","typeGuard":"def is_legal_path(p) -> bool:\n    if not isinstance(p, str) or not p.startswith('/') or len(p) == 0:\n        return False\n    return True","tryCatchPattern":"try:\n    from toolbox import run_gradio  # or the launch helper containing the check\n    run_gradio(demo, port=PORT, custom_path=CUSTOM_PATH)\nexcept RuntimeError as e:\n    if 'Illegal custom path' in str(e):\n        sys.exit('CUSTOM_PATH must start with \"/\" (e.g. \"/gpt-academic\"). Fix config_private.py.')\n    raise","preventionTips":["Always write CUSTOM_PATH with a leading slash and no scheme/host: '/gpt-academic', never 'gpt-academic' or a full URL.","Set CUSTOM_PATH explicitly to '/' for root deployments instead of leaving it empty or None.","Validate CUSTOM_PATH in your deployment script before launching the app."],"tags":["configuration","deployment","gradio","startup"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}