【问题标题】:Why my HTTP Post request not reading data from payload?为什么我的 HTTP Post 请求没有从有效负载中读取数据?
【发布时间】:2020-10-08 03:13:44
【问题描述】:

我正在编写以下代码,但发布请求未在界面控制台中打印给定数据。你能帮我解决一下吗?

import requests
pyload = {'id': 2,
        'Desc': IT}
res = requests.post('http://127.0.0.1:5000/ncc',data = pyload)
print(res.status_code)
print(res.text)
print(res.url)

【问题讨论】:

  • request is not loading the given data - 这是什么意思?您的回复有误?
  • “pyload”中的数据没有打印在界面控制台中。

标签: python api http-post


【解决方案1】:

改用json:

pyload = {'id': 2, 'Desc': IT}
res = requests.post('http://127.0.0.1:5000/ncc', json=pyload)

【讨论】:

    【解决方案2】:

    数据是一个字符串

    import json
    
    ...
    res = requests.post('http://127.0.0.1:5000/ncc',data = json.dumps(pyload))
    

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 1970-01-01
      • 2013-01-09
      • 2013-04-17
      • 2021-11-19
      • 2021-12-31
      • 2015-09-04
      • 2014-09-23
      相关资源
      最近更新 更多