ModuleNotFoundError: No module named 'jose'
Asked Answered
E

5

10

I am using python-social-auth in my django project to use social platforms for authentication in my project. It all worked well but am getting this error ModuleNotFoundError: No module named 'jose' This is the whole error:

[05/Apr/2020 14:01:00] "GET /accounts/login/ HTTP/1.1" 200 3058
Internal Server Error: /login/twitter/
Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\site-packages\social_core\backends\utils.py", line 50, in get_backend
    return BACKENDSCACHE[name]
KeyError: 'twitter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Ahmed\AppData\Roaming\Python\Python37\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:\Program Files\Python37\lib\site-packages\social_django\utils.py", line 46, in wrapper
    backend, uri)
  File "C:\Program Files\Python37\lib\site-packages\social_django\utils.py", line 27, in load_backend
    Backend = get_backend(BACKENDS, name)
  File "C:\Program Files\Python37\lib\site-packages\social_core\backends\utils.py", line 53, in get_backend
    load_backends(backends, force_load=True)
  File "C:\Program Files\Python37\lib\site-packages\social_core\backends\utils.py", line 35, in load_backends
    backend = module_member(auth_backend)
  File "C:\Program Files\Python37\lib\site-packages\social_core\utils.py", line 62, in module_member
    module = import_module(mod)
  File "C:\Program Files\Python37\lib\site-packages\social_core\utils.py", line 56, in import_module
    __import__(name)
  File "C:\Program Files\Python37\lib\site-packages\social\backends\google.py", line 3, in <module>
    from social_core.backends.google_openidconnect import GoogleOpenIdConnect
  File "C:\Program Files\Python37\lib\site-packages\social_core\backends\google_openidconnect.py", line 5, in <module>
    from .open_id_connect import OpenIdConnectAuth
  File "C:\Program Files\Python37\lib\site-packages\social_core\backends\open_id_connect.py", line 6, in <module>
    from jose import jwk, jwt
ModuleNotFoundError: No module named 'jose'
[05/Apr/2020 14:01:06] "GET /login/twitter/?next=/accounts/login/ HTTP/1.1" 500 132103

I am pretty new to python and can't figure out what the issue is.

Exemplify answered 6/4, 2020 at 13:53 Comment(1)
Could you please add the output of pip freeze?Twobyfour
C
22

Install jose by running:

pip install python-jose>=3.0.0
Clupeoid answered 6/4, 2020 at 14:14 Comment(0)
L
5
pip3 install social-auth-core[openidconnect]

python-jose is part of openid connect integration, the requirement is defined in requirements-openidconnect.txt and to install it you need to set the openidconnect extra require.

To mitigate this, add this dependency to your requirements.txt file: social-auth-core[openidconnect] or don't import openidconnect modules.

source: https://github.com/python-social-auth/social-app-django/issues/178

Libido answered 6/4, 2020 at 13:59 Comment(0)
F
2

I had faced a similar issue,where the module "python-jose" was installed but still thows the same error. Fixed by trying :

import jwt

Instead of :

from jose import jwt
Frigg answered 10/12, 2022 at 12:40 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Hortense
T
1

As explained by Vikas, this is an issue with the package. To solve it out you should just run the following command in your python environment:

pip install social-auth-core
Topic answered 6/4, 2020 at 14:2 Comment(1)
I run this but it says Requirement already satisfiedEndocrinotherapy
M
1

Installing python-jose as root user solves the issue for me on Linux Ubuntu 22.04.4 LTS x86_64.

The command:

sudo pip install python-jose

Import in Python 3.10.12 :

from jose import JWSError, jwt
Merkley answered 8/7 at 22:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.