Partial Response Error on Dockerized Flask API (long response)

Viewed 282

I have a Flask API (Python 3.5) that returns a complete response in my local setup. Currently, I have dockerized the application and now the app runs within the container in my local docker.

My current problem is that, when I send the same request to the same service inside the docker container, the response is truncated. Postman simply stops working and curl will return CURL_PARTIAL_RESPONSE error.

My actual full response is > 6 000 000 bytes. It is a long response. But from docker I get partial response and it appears cut off. Is there some environment variable or library that the docker container needs to have to not truncate this response? Or maybe is this some property related to flask?

I have the same setup locally and in local setup the response is not truncated. I suspect that the docker container has some settings due to which I get back a partial response. Any pointers on this is appreciated.

DockerFile:

FROM python:3.5

WORKDIR /worker_deploy

ADD trainer /worker_deploy/

RUN pip install -r requirements.txt

EXPOSE 80
EXPOSE 5000

ENTRYPOINT ["python","/service/run_docker_trainer.py"]

requirements.txt has some other libraries but I am including just python and flask versions:

   Flask==0.12.2   
   Python 3.5.0 

Start the container like this:

docker run -it -p 5000:5000 miracle

(miracle is my docker image and it starts on 0.0.0.0:5000)

And then I issue a POST request on 127.0.0.1/test and I get a response that is a JSON 1.6MB and I only receive partial output and curl says connection closed with curl(18) error: CURL_PARTIAL_RESPONSE

My code in flask returns response using "jsonify". So it is not a streamed response.

 @flask_app.route('/train', methods=['POST'])
        def train_model():
           trainer = worker.Worker(service_obj)
           ret = trainer.train_package()
           return jsonify(ret)
0 Answers
Related