Managing flask error by looping and not redirecting

Asked

Viewed 78 times

1

I set up a server that can send and receive files, with a size limit of 50mb using ['MAX_CONTENT_LENGTH'] = 50 * 1024 * 1024, I also made a Errohandler for Error 413, which is what I get when I send a large file. But when it receives the large file, the server plays the user in a loop 3 times, and then the browser shows an error of ERR_CONNECTION_ABORTED.

I tried using "413" on @app, "RequestEntityTooLarge", Both and it doesn’t change anything. I also tried to Return only with a message and error, only a message, a flash and then redirect back to the page or home, and nothing changed. Handler is executed, but does nothing I say to do, only makes the problem worse.

Error:

Não é possível acessar esse site
A página (papapa)/upload pode estar temporariamente indisponível ou pode ter sido movida permanentemente para um novo endereço da Web.
ERR_CONNECTION_ABORTED

Upload:

def upload():
    form = UploadForm()

    if request.method == 'POST':
        try:
            f = form.f.data
            path = 'files/.'
            files = os.listdir(path)

            if f.filename not in files:
                filesPath = 'files/'
                f.save(filesPath + secure_filename(f.filename))
                flash('O arquivo foi enviado.')
                return render_template('upload.html', form = form)

            elif f.filename in files:
                flash('Esse nome já foi usado.')
                return render_template('upload.html', form = form)
        except:
            print(sys.exc_info()[0])
            flash('Algo deu errado ao enviar seu arquivo.')
            return redirect(request.url)

    return render_template('upload.html', form = form)

Errohandler:

@app.errorhandler(413) #tentei RenquestEntityTooLarge
def error_413(e):
    flash('Seu arquivo é grande demais. Max: 50mb')
    return redirect(url_for('upload'))

Exit from the terminal:

POST /upload HTTP/1.1" 302 -
POST /upload HTTP/1.1" 302 -
POST /upload HTTP/1.1" 302 -

I’ve tried to use it too time.sleep(1) to give the browser time to load. Why does he loop and how do I redirect him after a mistake?

Edit1: I found that it works on mobile, but does not work on any computer, not even on a virtual machine using Hamachi. It cannot be cache or cookie since the modification is from the server, and I am not using any cookie.

  • Basically, I have the same problem this guy. And yes, I’m using another computer for testing, it’s no problem to be testing on the host

  • For some reason when I put that the maximum is only 50 bytes no error happens

  • depending on the file, it does what I want, or not

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.