import OAuth2Authentication ImportError: No module named 'oauth2_provider.ext'

731 Views Asked by At

I'm trying to login by Facebook in my python projcet .it keeps telling me that ImportError: No module named 'oauth2_provider.ext' whenever I migrate it using terminal


my installed using pip freeze :


certifi==2020.6.20
cffi==1.14.2
chardet==3.0.4
cryptography==3.1
defusedxml==0.7.0rc1
dj-database-url==0.5.0
Django==2.2.16
django-braces==1.14.0
django-oauth-toolkit==1.3.2
django-oauth2==3.0
django-rest-framework-social-oauth2==1.0.4
djangorestframework==3.11.1
gunicorn==19.6.0
idna==2.10
oauthlib==3.1.0
Pillow==3.3.0
pycparser==2.20
PyJWT==1.7.1
python-social-auth==0.3.6
python3-openid==3.2.0
pytz==2020.1
requests==2.24.0
requests-oauthlib==1.3.0
shortuuid==1.0.1
six==1.15.0
social-auth-app-django==1.1.0
social-auth-core==3.3.3
sqlparse==0.3.1
urllib3==1.25.10
whitenoise==3.2.1

and requirements.txt file contains:


Django==1.10
gunicorn==19.6.0
Pillow==3.3.0
whitenoise==3.2.1
dj-database-url==0.5.0
psycopg2==2.7.5
django-rest-framework-social-oauth2==1.0.4

and my runtime.txt file :


python-3.5.2

and the code I used to login by Facebook from the site I used in settings.py in


INSTALLED_APPS = [..,
'oauth2_provider',
    'social_django',
    'rest_framework_social_oauth2',
]

TEMPLATES = [ ...,
    'OPTIONS': {...,
    'social_django.context_processors.backends',
    'social_django.context_processors.login_redirect',
    ],
    
    
        AUTHENTICATION_BACKENDS = (
           'social_core.backends.facebook.FacebookOAuth2',
           'rest_framework_social_oauth2.backends.DjangoOAuth2',
           'django.contrib.auth.backends.ModelBackend',
        )
    
    
    
        SOCIAL_AUTH_FACEBOOK_KEY = '355645928947054'
        SOCIAL_AUTH_FACEBOOK_SECRET = 'c606775c70e7dc01626ee41cbf95a0b8'
    
    
    
        SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
        SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
            'fields': 'id, name, email'
        }
    

and in urls.py :

        in urlpatterns = [... ,
        ..,
            url(r'^api/social/', include('rest_framework_social_oauth2.urls')),
        ]
1

There are 1 best solutions below

0
On

solved by ➡️ pip install django-rest-framework-social-oauth2

not that version which caused that er ▶️ django-rest-framework-social-oauth2==1.0.4 and the error disappeard