docker 内的 Flask 未收到 json 请求

Flask inside docker does not get json requests

我的 flask 应用程序在 docker 容器内工作,没有收到 json 请求。 当我发送 json 请求时,我得到响应元组,看起来像那样(省略号,省略号)

我的端点

class WhoisInfo(Resource):
    def post(self):
        if request.method == "POST":
           logger.debug("got request method POST")
        if request.is_json:
            logger.debug("is json")
            logger.debug(request.args.get('host'))
            logger.debug(request.get_data())
    return {"error": "Not information about this zone "}, 400
api_v1.add_resource(WhoisInfo, "/api/whois/")

调试输出

backend_1  | 2021-10-03 13:03:30.582 | DEBUG    | api.views:post:53 - got request method POST
backend_1  | 2021-10-03 13:03:30.583 | DEBUG    | api.views:post:55 - is json
backend_1  | 2021-10-03 13:03:30.583 | DEBUG    | api.views:post:56 - (Ellipsis, Ellipsis)
backend_1  | 2021-10-03 13:03:30.583 | DEBUG    | api.views:post:57 - b'{"host": "8.8.8.8"}'

我的要求

import requests

url = "http://127.0.0.1:80/api/whois/"

payload={"host": "8.8.8.8"}
headers = {
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)


这个问题是因为Flask版本不对,我用的是python3.8和Flask 0.10.1,我把Flask版本改成2.0.2,一切正常。