首页 > 解决方案 > Python 请求发送空数据

问题描述

我正在使用 python 的请求模块发送一个发布请求:

res = requests.post('https://mysite.xyz/bot/upload',
                     headers={'Content-type': 'text/plain'},
                     data=data.encode('utf8'),
                     verify=True)

这是我用https://httpbin.org/post替换 url 时得到的(预期的)响应:

{
  "args": {}, 
  "data": "test data", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "*/*", 
    "Accept-Encoding": "gzip, deflate", 
    "Content-Length": "9", 
    "Content-Type": "text/plain", 
    "Host": "httpbin.org", 
    "User-Agent": "python-requests/2.20.1"
  }, 
  "json": null, 
  "origin": "<my IP address>, <my IP address>", 
  "url": "https://httpbin.org/post"
}

我发送数据的服务器使用烧瓶。这是代码:

@app.route('/bot/upload', methods=['POST', 'GET'])
def dataup():
    data = flask.request.data
    print(flask.request.content_type)
    print(data)
    # do stuff with it

这输出:

None
b''

出了什么问题?

标签: pythonflaskpython-requestshttp-post

解决方案


推荐阅读