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

Python发送form-data上传XLSX报错,Postman可正常运行求排查

POST上传XLSX接口Postman正常运行,Python代码报错排查

Postman中正常使用的profile参数

{
  "warnings_for_required_and_disabled_fields": true,
  "keep_locked": false,
   "doc_profile": {
      "name": "XLSX Upload",
      "type": "EXCELX"
    }
}

自行编写的Python代码

def UploadDocument():
 url = "example.url"

payload="{\"profile\":{\"warnings_for_required_and_disabled_fields\":true,\"keep_locked\":false,\"doc_profile\":{\"name\":\"XLSXUpload\",\"type\":\"EXCELX\"}}}"
files={
    "file": ('example.xlsx', open(r'C:\example\example\example.xlsx','rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', None)
}

headers = {
    'X-Auth-Token': 'SomeToken',
    'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
}
response = requests.post(url, headers=headers, data=json.loads(payload), files=files)
print(response.text)

返回的异常信息

{"error":{"code":"NRC_FAILURE","code_message":"Operation Failed","detailed_error_message":"The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.","dms_version":"10.4.5.593","function":"handle_exception"}}

已尝试但无效的操作

  • 直接使用Postman生成的Python代码
  • 将JSON字符串化后传入
  • 使用Python requests的json参数传递数据
  • 修改请求头配置
  • 从JSON文件加载profile键值

恳请协助排查问题。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 00:15:16