✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Invalid Start Byte when trying to route to Dash App from Flask

from flask import Blueprint, Flask, jsonify, redirect, render_template_string, url_for
from flask_oidc import OpenIDConnect
from okta import UsersClient
import dash

oidc = OpenIDConnect()
okta_client = UsersClient("https://dev-XXXXXX.okta.com",
            "somesecret")

app = Flask(__name__)

app.config.from_mapping(
SECRET_KEY="testkey",
OIDC_CLIENT_SECRETS="/app/appname/client_secrets.json",
OIDC_COOKIE_SECURE= False,
OIDC_CALLBACK_ROUTE="/oidc/callback",
OIDC_SCOPES=["openid", "email", "profile"],
OIDC_ID_TOKEN_COOKIE_NAME="oidc_token",
DEBUG_TB_INTERCEPT_REDIRECTS = False)

oidc.init_app(app)

dash_app.layout = layout.layout
callbacks.register_dash_callbacks(dash_app)
dash_app.run_server(debug=True)

@app.route("/" , methods=["GET"])
@oidc.require_login
def redirect_to_app():
    return redirect(url_for(dash_app.config.requests_pathname_prefix))

gives me the following:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte

The app works just fine and integrates well into the Flask app. I’ve tried researching but wasn’t able to find anything useful.

I could also get it to work by separating it out into a blueprint like so:

home_blueprint = Blueprint("home", __name__, url_prefix="/")
@home_blueprint.route("/" , methods=["GET"])
@oidc.require_login
def index():
    return redirect(url_for('/dash/'))

But then accessing the app directly via localhost:5000/dash/ was still possible without authorization.

Thank you in advance for your help.
Here the complete traceback:

Traceback (most recent call last):
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/vendor/wrapt/wrappers.py", line 602, in __call__
    return self._self_wrapper(self.__wrapped__, self._self_instance,
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/helpers.py", line 20, in wrapper
    return func(pin, wrapped, instance, args, kwargs)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/patch.py", line 331, in traced_wsgi_app
    return wrapped(environ, start_response)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/vendor/wrapt/wrappers.py", line 602, in __call__
    return self._self_wrapper(self.__wrapped__, self._self_instance,
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/helpers.py", line 20, in wrapper
    return func(pin, wrapped, instance, args, kwargs)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/helpers.py", line 29, in wrapper
    return wrapped(*args, **kwargs)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 1816, in full_dispatch_request
    return self.finalize_request(rv)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 1833, in finalize_request
    response = self.process_response(response)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/vendor/wrapt/wrappers.py", line 602, in __call__
    return self._self_wrapper(self.__wrapped__, self._self_instance,
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/helpers.py", line 20, in wrapper
    return func(pin, wrapped, instance, args, kwargs)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/helpers.py", line 29, in wrapper
    return wrapped(*args, **kwargs)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask/app.py", line 2112, in process_response
    response = handler(response)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/vendor/wrapt/wrappers.py", line 554, in __call__
    return self._self_wrapper(self.__wrapped__, instance,
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/ddtrace/contrib/flask/wrappers.py", line 23, in trace_func
    return wrapped(*args, **kwargs)
  File "/pyenv/versions/3.8.0/envs/customer-feedback-hub/lib/python3.8/site-packages/flask_debugtoolbar/__init__.py", line 202, in process_response
    response_html = response.data.decode(response.charset)