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

Postman请求正常但Python发送API POST请求失败原因咨询

请求失败原因及修复方案

核心问题

Postman发送表单POST请求时,默认采用multipart/form-data格式提交数据,但你用Python requests.post的data参数时,发送的是application/x-www-form-urlencoded格式。你调用的API(从路径看是IPFS节点的/api/v0/add接口)仅支持解析multipart/form-data格式下的path参数,无法识别application/x-www-form-urlencoded里的参数,因此返回"file argument 'path' is required"错误。

修复方法

根据你的需求选择对应方式:

  • 上传本地文件:用files参数模拟Postman的表单上传逻辑:
    import requests
    response = requests.post('http://127.0.0.1:5001/api/v0/add', files={'path': open('test', 'rb')})
    print(response.text)
    
  • 仅传递路径字符串:如果不需要上传文件内容,只是传递路径参数,可通过files参数传递纯字符串值(None表示不指定文件名):
    import requests
    response = requests.post('http://127.0.0.1:5001/api/v0/add', files={'path': (None, 'test')})
    print(response.text)
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 09:35:23