[ISSUE] Workspace Client files.download fails in Databricks App

未关闭
#1,272 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@deepan-crypto 已经在做这个了。

开始于 2026年10月3日。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
python

调研方向

首先,使用 x-forwarded-access-token 复现 WorkspaceClient.files.download,并将其与 issue 中描述的直接 GET 请求进行比较。沿着 traceback 路径检查 databricks/sdk/mixins/files.py、databricks/sdk/service/files.py、databricks/sdk/core.py 和 databricks/sdk/_base_client.py。完成的标准是:使用已部署应用的 token 时客户端下载能够正常工作,并且权限范围行为有覆盖测试。

由索引模型根据 Issue 内容生成。

描述

Description
When using the files.download method in the Workspace Client, this works locally with an injected user access token but failing with the downscoped user-authorisation x-forwarded-access-token.
When calling the GET API directly at <host>/api/2.0/fs/files this works fine for both local and deployed Databricks App.

Reproduction

@router.get("/get_image/{image_path:path}")
async def get_databricks_image(
    request: Request,
    image_path: str):
    from databricks.sdk.core import Config
    from Databricks.sdk import WorkspaceClient
    import jwt
    import databricks
    
    access_token = request.headers.get("x-forwarded-access-token")

    try:
        cfg = Config(host=<HOST>,
            token=access_token,
            auth_type="pat",
            )
       
        w = WorkspaceClient(config=cfg)
 
        logger.info(f"Fetching image from Databricks: {image_path}")
 
        resp: DownloadResponse = w.files.download(image_path)
        # Get binary image content
        image_bytes = resp.contents.read()
 
        # Convert binary image to base64 string
        image_base64 = base64.b64encode(image_bytes).decode('utf-8')
           
    except Exception as e:
        logger.error(f"Full traceback:\n{traceback.format_exc()}")
 
        return JSONResponse(
            status_code=500,
            content={"error": str(e)},
        )
   
    return JSONResponse(content={"image_data": image_base64, "path": image_path})

Expected behavior
This works when testing locally with a Workspace level Admin account by using Databricks auth login and then adding a middleware in FastAPI to inject the x-forwarded-access-token by reading the access_token from the local ~/.databricks/token-cache.json file.
When deployed to Databricks App, this errors out:
databricks.sdk.errors.platform.PermissionDenied: Provided OAuth token does not have required scopes

Is it a regression?
Not a regression AFAIK

Debug Logs

2026-02-18 04:26:46,783 [ERROR] Full traceback: Traceback (most recent call last):   File "/app/python/source_code/routes/v1/image_search.py", line 271, in get_databricks_image     resp: DownloadResponse = w.files.download(image_path)                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/mixins/files.py", line 800, in download     return super().download(file_path)            ^^^^^^^^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/service/files.py", line 881, in download     res = self._api.do(           ^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/core.py", line 86, in do     return self._api_client.do(            ^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/_base_client.py", line 199, in do     response = call(                ^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/retries.py", line 59, in wrapper     raise err   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/retries.py", line 38, in wrapper     return func(*args, **kwargs)            ^^^^^^^^^^^^^^^^^^^^^   File "/app/python/source_code/.venv/lib/python3.11/site-packages/databricks/sdk/_base_client.py", line 301, in _perform     raise error from None

Other Information
Databricks SDK version: 0.83.0

Additional context
Pair programming session done with Databricks engineer Naim on 13th of February 2026 to diagnose issue. Implementation changed to raw HTTP request instead of workspace client.

主要语言
Python
星标
577
派生
229
平均合并
40 分钟
30 天内合并 PR
12

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

databricks/databricks-sdk-py 的其他 Issue

查看 databricks/databricks-sdk-py 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。