Unexpected error when logging in NetBox via Keycloak #7183

Closed
opened 2025-12-29 20:20:16 +01:00 by adam · 3 comments
Owner

Originally created by @m-shalenko on GitHub (Nov 1, 2022).

NetBox version

v3.3.6

Python version

3.8

Steps to Reproduce

  1. I have built netbox with such params to integrate it with keycloak using this documentation https://demo.netbox.dev/static/docs/installation/ and https://demo.netbox.dev/static/docs/administration/authentication/overview/#single-sign-on-sso
SOCIAL_AUTH_KEYCLOAK_KEY = oidc
SOCIAL_AUTH_KEYCLOAK_SECRET = **************
SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY = *************
SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL = https://auth.example.com/realms/example/protocol/openid-connect/auth
SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL = https://auth.example.com/realms/example/protocol/openid-connect/token
SOCIAL_AUTH_KEYCLOAK_ID_KEY = email
REMOTE_AUTH_BACKEND = 'social_core.backends.keycloak.KeycloakOAuth2'
  1. Eventually, when I try to login using Keycloak single sign-on provider I run into an error
Server Error
A module import error occurred during this request. Common causes include the following:

Missing required packages - This installation of NetBox might be missing one or more required Python packages. These packages are listed in requirements.txt and local_requirements.txt, and are normally installed as part of the installation or upgrade process. To verify installed packages, run pip freeze from the console and compare the output to the list of required packages.

WSGI service not restarted after upgrade - If this installation has recently been upgraded, check that the WSGI service (e.g. gunicorn or uWSGI) has been restarted. This ensures that the new code is running.

The complete exception is provided below:

<class 'ModuleNotFoundError'>

No module named 'netbox.users'

Python version: 3.8.10
NetBox version: 3.3.6
If further assistance is required, please post to the [NetBox discussion forum](https://github.com/netbox-community/netbox/discussions) on GitHub.
image image
  1. By the way, I decide to check if module exists. Attached the output from command line below.
# ls -la /opt/netbox/netbox/users/
total 88
drwxrwxr-x  8 root root  4096 Nov  1 17:01 .
drwxrwxr-x 19 root root  4096 Nov  1 11:51 ..
drwxrwxr-x  3 root root  4096 Oct 31 22:33 admin
drwxrwxr-x  3 root root  4096 Oct 31 22:33 api
-rw-rw-r--  1 root root   313 Oct 26 17:18 constants.py
-rw-rw-r--  1 root root  4111 Oct 26 17:18 filtersets.py
-rw-rw-r--  1 root root  3810 Oct 26 17:18 forms.py
drwxrwxr-x  3 root root  4096 Oct 31 22:33 graphql
-rw-rw-r--  1 root root     0 Oct 26 17:18 __init__.py
drwxrwxr-x  3 root root  4096 Oct 31 22:33 migrations
-rw-rw-r--  1 root root  9694 Oct 26 17:18 models.py
-rw-rw-r--  1 root root   371 Oct 26 17:18 preferences.py
drwxr-xr-x  2 root root  4096 Oct 31 22:33 __pycache__
-rw-rw-r--  1 root root  1094 Oct 26 17:18 tables.py
drwxrwxr-x  2 root root  4096 Oct 26 17:18 tests
-rw-rw-r--  1 root root   655 Oct 26 17:18 urls.py
-rw-rw-r--  1 root root   292 Oct 26 17:18 utils.py
-rw-rw-r--  1 root root 10673 Oct 26 17:18 views.py

Expected Behavior

I expect redirecting to keycloak auth page to login into netbox

Observed Behavior

I get the error about absence of module 'netbox.users'

Originally created by @m-shalenko on GitHub (Nov 1, 2022). ### NetBox version v3.3.6 ### Python version 3.8 ### Steps to Reproduce 1. I have built netbox with such params to integrate it with keycloak using this documentation https://demo.netbox.dev/static/docs/installation/ and https://demo.netbox.dev/static/docs/administration/authentication/overview/#single-sign-on-sso ``` SOCIAL_AUTH_KEYCLOAK_KEY = oidc SOCIAL_AUTH_KEYCLOAK_SECRET = ************** SOCIAL_AUTH_KEYCLOAK_PUBLIC_KEY = ************* SOCIAL_AUTH_KEYCLOAK_AUTHORIZATION_URL = https://auth.example.com/realms/example/protocol/openid-connect/auth SOCIAL_AUTH_KEYCLOAK_ACCESS_TOKEN_URL = https://auth.example.com/realms/example/protocol/openid-connect/token SOCIAL_AUTH_KEYCLOAK_ID_KEY = email REMOTE_AUTH_BACKEND = 'social_core.backends.keycloak.KeycloakOAuth2' ``` 2. Eventually, when I try to login using Keycloak single sign-on provider I run into an error ``` Server Error A module import error occurred during this request. Common causes include the following: Missing required packages - This installation of NetBox might be missing one or more required Python packages. These packages are listed in requirements.txt and local_requirements.txt, and are normally installed as part of the installation or upgrade process. To verify installed packages, run pip freeze from the console and compare the output to the list of required packages. WSGI service not restarted after upgrade - If this installation has recently been upgraded, check that the WSGI service (e.g. gunicorn or uWSGI) has been restarted. This ensures that the new code is running. The complete exception is provided below: <class 'ModuleNotFoundError'> No module named 'netbox.users' Python version: 3.8.10 NetBox version: 3.3.6 If further assistance is required, please post to the [NetBox discussion forum](https://github.com/netbox-community/netbox/discussions) on GitHub. ``` <img width="646" alt="image" src="https://user-images.githubusercontent.com/86623392/199261323-b9c6742d-de59-4a26-8c69-bfa6d1bf3ee3.png"> <img width="806" alt="image" src="https://user-images.githubusercontent.com/86623392/199261373-3ac3f101-36f5-4c09-9657-42b161611e25.png"> 3. By the way, I decide to check if module exists. Attached the output from command line below. ```bash # ls -la /opt/netbox/netbox/users/ total 88 drwxrwxr-x 8 root root 4096 Nov 1 17:01 . drwxrwxr-x 19 root root 4096 Nov 1 11:51 .. drwxrwxr-x 3 root root 4096 Oct 31 22:33 admin drwxrwxr-x 3 root root 4096 Oct 31 22:33 api -rw-rw-r-- 1 root root 313 Oct 26 17:18 constants.py -rw-rw-r-- 1 root root 4111 Oct 26 17:18 filtersets.py -rw-rw-r-- 1 root root 3810 Oct 26 17:18 forms.py drwxrwxr-x 3 root root 4096 Oct 31 22:33 graphql -rw-rw-r-- 1 root root 0 Oct 26 17:18 __init__.py drwxrwxr-x 3 root root 4096 Oct 31 22:33 migrations -rw-rw-r-- 1 root root 9694 Oct 26 17:18 models.py -rw-rw-r-- 1 root root 371 Oct 26 17:18 preferences.py drwxr-xr-x 2 root root 4096 Oct 31 22:33 __pycache__ -rw-rw-r-- 1 root root 1094 Oct 26 17:18 tables.py drwxrwxr-x 2 root root 4096 Oct 26 17:18 tests -rw-rw-r-- 1 root root 655 Oct 26 17:18 urls.py -rw-rw-r-- 1 root root 292 Oct 26 17:18 utils.py -rw-rw-r-- 1 root root 10673 Oct 26 17:18 views.py ``` ### Expected Behavior I expect redirecting to keycloak auth page to login into netbox ### Observed Behavior I get the error about absence of module 'netbox.users'
adam added the type: bugstatus: duplicate labels 2025-12-29 20:20:16 +01:00
adam closed this issue 2025-12-29 20:20:16 +01:00
Author
Owner

@m-shalenko commented on GitHub (Nov 1, 2022):

A while ago I noticed that I have already been logged in gmail (identity provider for my keycloak instance) in the current browser so I tried to login via private mode and successfully authenticated but after that I have seen the same error again instead of the main page of NetBox.

@m-shalenko commented on GitHub (Nov 1, 2022): A while ago I noticed that I have already been logged in gmail (identity provider for my keycloak instance) in the current browser so I tried to login via private mode and successfully authenticated but after that I have seen the same error again instead of the main page of NetBox.
Author
Owner

@m-shalenko commented on GitHub (Nov 1, 2022):

I decided to find out what is the problem and want to share with you

I changed SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'netbox.users.utils.clean_username' to SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'users.utils.clean_username' in this file /opt/netbox/netbox/netbox/settings.py and that's it! It works now! I have successfully logged in netbox.

@m-shalenko commented on GitHub (Nov 1, 2022): I decided to find out what is the problem and want to share with you I changed **SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'netbox.users.utils.clean_username'** to **SOCIAL_AUTH_CLEAN_USERNAME_FUNCTION = 'users.utils.clean_username'** in this file /opt/netbox/netbox/netbox/settings.py and that's it! It works now! I have successfully logged in netbox.
Author
Owner

@kkthxbye-code commented on GitHub (Nov 1, 2022):

Duplicate of https://github.com/netbox-community/netbox/issues/10770

Will be fixed in the next release.

@kkthxbye-code commented on GitHub (Nov 1, 2022): Duplicate of https://github.com/netbox-community/netbox/issues/10770 Will be fixed in the next release.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7183