Error 413 (Request Entity Too Large)

Hey all,

Desperately need some help here.
I built an application that allows users to select and plot large sets of data. I have a callback that is triggered on a chart relayout (Input(‘chart’, ‘relayoutData’)) and takes in the chart figure as a state (State(‘chart’, ‘figure’)) so that I don’t have to make subsequent api calls for the same data.

The problem I’m running into is when the chart’s layout changes, and the callback is triggered, I get a 413 error. I understand that this error is generated because I’m trying to pass a large amount of data (~2MB) back to the server in the chart’s figure object. However, I don’t know how to fix the error. The flask documentation (here) recommends increasing the max content length via the following code:

from flask import Flask, Request
app = Flask(name)
app.config[‘MAX_CONTENT_LENGTH’] = 16 * 1024 * 1024

but that didn’t remedy the issue. Any other thoughts? Also, the app was working perfectly until I repackaged and redeployed the code today. Any ideas why this suddenly became an issue? Thought it might be a chrome thing, but I get the same result in internet explorer.

Thanks in advance for your help.

3 Likes

Are you running locally, or in a production environment? Are you using nginx or similar?

@Emil I tested both locally and in a production environment (using waitress and the default flask server). I only get the error in the production environment though. Running locally works just fine.

Thanks for your help.

@Emil Reviving a dead thread here - I have run into this error recently as well. I’ve been standing up Dash apps as local containers and within shinyproxy with no issues for a few years now, but ran into the exact same issue as @ajrehl1 upon doing a standalone k8s deployment using nginx as an ingress controller.

The app is able to retrieve data from an external API without issue and store it in a dash_table, but upon trying to read data from the stored table (in this case, finding items from the active_row selected), it errors out and provides a 413. I put a row limiter on there and file size log statement, and found that this happens almost exactly at 1mb stored locally in the session.

Do you have any ideas what may be causing this?

Thanks!

There is likely a server “in the middle” (like nginx or a load balancer) when you deploy apps on your own. That server will need to be modified to have a larger request entities. Depending on the environment, it’s not always possible to customize this.

If you are deploying apps with the Dash Enterprise platform, we remove this Request Entity limitation within the middleware and you don’t need to worry about it.

In my case, I saw the error because my Dash app was served via an API gateway (it was an app developed at work), i.e. very much in line with the suggestion by @chriddyp . Since requesting changes in IT infrastructure is a slow process at our company (even if it was approved, it could take months), I ended up changing my implementation so as to circumvent the error instead.

Thanks for the replies. I ended up getting it sorted out - it was the client_max_body_size argument in the nginx config in my helm charts. It defaults to 1mb, which was coincidentally the exact limit of data my app could store on the page before returning a 413 (and helped point me in the right direction).

3 Likes

Thanks. This helped me fix my issue.