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
相关产品推荐
相关产品推荐

