Python请求发送空数据

时间:2019-10-19 13:21:23

标签: python flask python-requests http-post

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

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

这是我将网址替换为https://httpbin.org/post时得到的(预期)响应:

{
  "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"
}

我要将数据发送到的服务器使用flask。这是代码:

@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''

出了什么问题?

0 个答案:

没有答案