My flask application, whose works inside a docker container, does not get json requests. When I sent json request I get tuple in response, looks like that(Ellipsis, Ellipsis)
My endpoint
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/")
debug output
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"}'
My request
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)
CodePudding user response:
This problem come from the wrong Flask version, I used python3.8 and Flask 0.10.1, I changed Flask version to 2.0.2 and everything works.