问题概述
PR #42 合并后发布了 v0.0.16 版本,声称修复了 Issue #41 中报告的 post_file() 和 get_file() 方法缺少 auth() 调用的问题。但是该修复并未生效 ,仍然出现 401 未授权错误。
环境信息
agentrun-sdk 版本:0.0.16 (从 0.0.14 升级)
Python 版本:3.12
操作系统:Windows 10
问题时间线
Issue post_file() and get_file() methods missing auth() call in DataAPI #41 报告了 post_file() 和 get_file() 缺少 auth() 调用
PR Add missing auth() calls to file upload/download methods #42 由 Copilot 创建,声称添加了缺失的 auth() 调用
v0.0.16 版本发布
问题依旧 - 仍然出现 401 错误
复现步骤
from agentrun .sandbox import Sandbox , TemplateType
sandbox = Sandbox .create (
template_type = TemplateType .AIO ,
template_name = "your-template-name" ,
)
sandbox .__enter__ ()
# 在 v0.0.16 中仍然报 401 错误
result = sandbox .file_system .upload (
local_file_path = "local_file.txt" ,
target_file_path = "/tmp/file.txt"
)
错误信息(与之前相同)
{
"code" : " ERR_UNAUTHORIZED" ,
"requestId" : " ..." ,
"message" : " missing API key in header X-API-Key or query parameter"
}
源码验证
检查 v0.0.16 版本的 .venv/Lib/site-packages/agentrun/utils/data_api.py 源码:
post_file() 方法(约 880-935 行):
def post_file (self , path , local_file_path , target_file_path , ...):
url = self .with_path (path , query = query )
req_headers = self .config .get_headers ()
req_headers .update (headers or {})
# ❌ 这里仍然没有 auth() 调用!
try :
with open (local_file_path , "rb" ) as f :
# ... 直接发起请求,没有认证 headers
正确写法(参考 get_video() 方法):
def get_video (self , path , save_path , ...):
url = self .with_path (path , query = query )
req_headers = self .config .get_headers ()
req_headers .update (headers or {})
# ✅ 正确 - 调用 auth() 添加认证 token
cfg = Config .with_configs (self .config , config )
url , req_headers , query = self .auth (url , req_headers , query , config = cfg )
Copilot 修复失败的原因分析
根据 PR #42 中 Copilot 的评论,它声称做了以下修改:
Changes:
agentrun/utils/__data_api_async_template.py: Added auth() calls to post_file_async() and get_file_async()
agentrun/utils/data_api.py: Regenerated via codegen , propagating auth() to all four methods (sync + async variants)
问题:codegen 没有正确执行
Copilot 修改了模板文件 (__data_api_async_template.py),然后依赖 make codegen 重新生成 data_api.py。
但是,检查 v0.0.16 版本中实际的 data_api.py 源码,发现 post_file() 和 get_file() 方法中仍然没有 auth() 调用 !
这说明 codegen 步骤失败了 :
Copilot 确实修改了模板文件 ✅
但 make codegen 执行失败或没有正确生成 data_api.py ❌
CI 检查失败(验证了 codegen 输出不一致)
尽管 CI 失败,PR 还是被合并了,发布了一个没有真正修复 的版本
证据
检查项
预期
实际
data_api.py 中 post_file() 有 auth()
✅ 有
❌ 没有
data_api.py 中 get_file() 有 auth()
✅ 有
❌ 没有
CI Run 93/94 状态
✅ success
❌ failed
建议的修复方案
在 agentrun/utils/data_api.py 的 post_file() 方法中添加 auth() 调用:
def post_file (self , path , local_file_path , target_file_path , ...):
url = self .with_path (path , query = query )
req_headers = self .config .get_headers ()
req_headers .update (headers or {})
# 添加这行代码(与 get_video() 方法一致):
cfg = Config .with_configs (self .config , config )
url , req_headers , query = self .auth (url , req_headers , query , config = cfg )
# ... 方法的其余部分
同样的修复也需要应用于 get_file()、post_file_async() 和 get_file_async() 方法。
临时解决方案
在官方修复之前,用户可以手动调用 auth() 获取认证 headers:
sandbox = self ._get_sandbox ()
# 手动获取认证 headers
_ , auth_headers , _ = sandbox .data_api .auth ()
# 将 headers 传递给 post_file/get_file
result = sandbox .data_api .post_file (
path = "/filesystem/upload" ,
local_file_path = str (local_path ),
target_file_path = remote_path ,
headers = auth_headers , # <-- 手动传入认证 headers
)
请求
请确认 PR Add missing auth() calls to file upload/download methods #42 的改动是否真正包含在 v0.0.16 中
如果没有,请发布包含正确修复的 v0.0.17 版本
建议添加文件上传/下载的集成测试,防止类似问题再次发生
相关:Issue #41 、PR #42
问题概述
PR #42 合并后发布了 v0.0.16 版本,声称修复了 Issue #41 中报告的
post_file()和get_file()方法缺少auth()调用的问题。但是该修复并未生效,仍然出现 401 未授权错误。环境信息
问题时间线
post_file()andget_file()methods missingauth()call in DataAPI #41 报告了post_file()和get_file()缺少auth()调用复现步骤
错误信息(与之前相同)
{ "code": "ERR_UNAUTHORIZED", "requestId": "...", "message": "missing API key in header X-API-Key or query parameter" }源码验证
检查 v0.0.16 版本的
.venv/Lib/site-packages/agentrun/utils/data_api.py源码:post_file()方法(约 880-935 行):正确写法(参考
get_video()方法):Copilot 修复失败的原因分析
根据 PR #42 中 Copilot 的评论,它声称做了以下修改:
问题:codegen 没有正确执行
Copilot 修改了模板文件 (
__data_api_async_template.py),然后依赖make codegen重新生成data_api.py。但是,检查 v0.0.16 版本中实际的
data_api.py源码,发现post_file()和get_file()方法中仍然没有 auth() 调用!这说明 codegen 步骤失败了:
make codegen执行失败或没有正确生成data_api.py❌证据
data_api.py中post_file()有 auth()data_api.py中get_file()有 auth()建议的修复方案
在
agentrun/utils/data_api.py的post_file()方法中添加 auth() 调用:同样的修复也需要应用于
get_file()、post_file_async()和get_file_async()方法。临时解决方案
在官方修复之前,用户可以手动调用
auth()获取认证 headers:请求
相关:Issue #41、PR #42