Dash Auth throwing error

Hello,
I have implemented basic dash_auth. After couple of days of running my application is throwing the below mentioned error. Let me know how to solve it.

File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/flask/app.py", line 2070, in wsgi_app
web: response = self.full_dispatch_request()
web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/flask/app.py", line 1515, in full_dispatch_request
web: rv = self.handle_user_exception(e)
web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/flask/app.py", line 1513, in full_dispatch_request
web: rv = self.dispatch_request()
web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/flask/app.py", line 1499, in dispatch_request
web: return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/dash_auth/basic_auth.py", line 30, in wrap
web: if not self.is_authorized():
web: File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/dash_auth/basic_auth.py", line 17, in is_authorized
web: username_password = base64.b64decode(header.split('Basic ')[1])
web: IndexError: list index out of range

versions:

dash==1.20.0
dash-auth==1.3.2

Any help would be appreciated. Thanks

Hi @Yadvendar

IndexError: list index out of range means that when is searching the index exceeds the number of element of the list.

Be sure that base64.b64decode(header.split('Basic ') has at least two elements.

Hello @Eduardo ,

I’m using the dash auth as described here in basic auth section: Add Authentication to your Dash App | Dash for Python Documentation | Plotly

i have my config file in which i have stored password and username like this:

appusername = "plolty"

apppassword = "plotly"

then i call them using VALID_USERNAME_PASSWORD_PAIRS = {config.appusername: config.apppassword}

and after instantiating the app i have added the authentication:

auth = dash_auth.BasicAuth(app, VALID_USERNAME_PASSWORD_PAIRS)

So why its throwing an error of list index out range, if its there available.

Thank you

I’m not sure because I never used it, but the documentation says that you have to store the data as a dictionary of pairs, that means {“your_username”: “your_password”} and then the base64.b64decode(header.split('Basic ')[1]) will try to find the password as a second element [1]

Hello,

If you look closely, I have mentioned that I retrieved them from config file and stored them as a dictionary pair as:

import config
VALID_USERNAME_PASSWORD_PAIRS = {config.appusername: config.apppassword}

I don’t know what i’m doing wrong here. It works fine sometimes, and then it breaks on its own.

Thank you for your help. If you find any solution, please keep me posted