You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将上传至Galaxy Store的有效Curl转换为Python Requests并排查代码问题

问题排查

你的Python代码存在三个核心错误:

  • 手动设置了Content-Type: multipart/form-data请求头:使用requests库的files参数上传文件时,requests会自动生成带boundary分隔符的multipart/form-data请求头,你手动填写的请求头缺少boundary参数,服务端无法拆分识别表单内容。
  • files参数结构错误:curl命令中type=image/png、filename="ICON_512x512.png"是file字段的附属属性,不是独立的表单字段;sessionId是普通文本表单字段,不应该放在files参数中,需要放到data参数传递。
  • 文件对象未正确关闭:直接调用open()打开文件后没有释放资源,存在泄漏风险。
修正后的代码
import requests

# 替换为实际的参数值
access_token = "<your-access-token>"
service_account_id = "<your-service-account-id>"
session_id = "<session-id>"

headers = {
    "Authorization": f"Bearer {access_token}",
    "service-account-id": service_account_id
}

# 普通文本表单字段统一放在data参数中
data = {
    "sessionId": session_id
}

# 文件字段格式为 (自定义文件名, 文件对象, 文件MIME类型)
with open("./ICON_512x512.png", "rb") as f:
    files = {
        "file": ("ICON_512x512.png", f, "image/png")
    }
    response = requests.post(
        "https://seller.samsungapps.com/galaxyapi/fileUpload",
        headers=headers,
        data=data,
        files=files
    )

# 调试时可打印返回信息排查问题
print(response.status_code)
print(response.text)

内容的提问来源于stack exchange,提问作者Mikhail

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 16:39:02