[ISSUE] Workspace Client files.download fails in Databricks App
维护者通常 1 天内回复
@deepan-crypto 已经在做这个了。
开始于 2026年10月3日。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- api, authentication
调研方向
首先,使用 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
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
databricks/databricks-sdk-py 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 62/100
databricks/databricks-sdk-py#1602 · 2 个 reaction ·
维护者通常 1 天内回复
-
[ISSUE] Docs state serving endpoints support at most ten served entities; actual limit is 15可能已有人在做 @divya0709 于 95 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
databricks/databricks-sdk-py#1496 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
databricks/databricks-sdk-py#1495 · 1 条评论 ·
维护者通常 1 天内回复
-
[ISSUE] `get_api_error` fails with `TypeError: object of type '_io.BufferedReader' has no len()¨`可能已有人在做 @mittalpk 于 111 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
databricks/databricks-sdk-py#1489 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
databricks/databricks-sdk-py#1451 ·
维护者通常 1 天内回复
查看 databricks/databricks-sdk-py 的全部 Issue
相似的 Issue
-
Unknown stop ID in slow zone data crashes post formatting and skips the rest of that day's posts未关闭backend bug tm-new-volunteer
难度 2/5 1-3 小时 新手友好度 84/100
transitmatters/mbta-slow-zone-bot#81 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
spacetelescope/rdmt-spire#49 ·
维护者通常 1 天内回复
-
AI bug
难度 2/5 1-3 小时 新手友好度 68/100
AUTO-MAS-Project/AUTO-MAS#1960 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
btclib-org/btclib-wallet#872 ·
维护者通常 1 天内回复