0

I get a net::ERR_EMPTY_RESPONSE error:

  • only on deployed version, not localhost
  • other GET-requests work

It downloads all my files from the ftp-server but it returns an error.:(

Flask Backend:

app = Flask(__name__)
cors = CORS(app)

@app.route('/downloadftp', methods=['POST'])
@cross_origin()
def download_all_ftp_data():
    # connect to sever...
    # download files...
    for f in ftp.nlst():
         fhandle = open(f, 'wb')
         ftp.retrbinary('RETR ' + f, fhandle.write)

    ftp.quit()
   
    return 'OK 200'

React Frontend:

useEffect(() => {
    axios
      .post(`${process.env.REACT_APP_HOST}/downloadftp`, { content: "post" })
      .then(res => {
        console.log(res)
        setError(false)
      })
      .catch(function (err) {
        console.log(err)
        setError(true)
      })
  }, [])
rebekka
  • 51
  • 6

1 Answers1

0

The error is due to the amount of data to download as it is described here: getting this net::ERR_EMPTY_RESPONSE error in browser

The solution for my problems was creating a daemon thread. The response is sent directly after starting the background thread.

from multiprocessing import Process

@app.route('/downloadftp')
@cross_origin()
def get_all_ftp_data():
    """creates a daemon thread for downloading all files while the response it sent directly after starting the background thread."""
    daemon_process = Process(
        target=download_data_multiprocessing,
        daemon=True
    )
    daemon_process.start()
    return Response(status=200)


def download_data_multiprocessing():
    """triggers download current data from ftp server"""
   
    # connect to sever
    # download
    for f in ftp.nlst():
        if (f != '.' and f != '..' and "meteo" not in f):
            fhandle = open(f, 'wb')
            ftp.retrbinary('RETR ' + f, fhandle.write)

    ftp.quit()
rebekka
  • 51
  • 6