Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES' - django

It's the first time I work with django rest and Django Oauth toolkit
I'm following this tutorial
oauth2-with-django-rest-framework
But when I run python manage.py migrate I get the following error:
ImportError: Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named ext.rest_framework.
What is going wrong ? is there another module I should install ?
my virtual environment contains :
certifi==2017.4.17
chardet==3.0.4
Django==1.11.2
django-extensions==1.8.1
django-oauth-toolkit==1.0.0
djangorestframework==3.6.3
idna==2.5
oauthlib==2.0.2
pytz==2017.2
requests==2.18.1
six==1.10.0
Unidecode==0.4.21
urllib3==1.21.1

It looks like oath2_provider.ext has been moved to oauth_provider.contrib. You could try installing an older version of django-oauth-toolkit, or try changing the value in DEFAULT_AUTHENTICATION_CLASSES from:
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
to:
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
Note that the tutorial is a couple of years old, you might find other problems like this.

I was facing same issue. In my setting file DEFAULT_AUTHENTICATION_CLASSES was already
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
I just installed older version as #Alasdair ask. My issue resolved. thanks

Related

Set up django-celery-email for local dev

It seems the best way to send emails from the django-allauth app asynchronously is to simply install django-celery-email. But the packages warns that
This version requires the following versions:Python 2.7 and Python3.5, Django 1.11, 2.1, and 2.2 Celery 4.0
I've only been using python for several months and never encountered a situation where two python version are needed on a project. And I'm using the official recommendation of pipenv for local development. A quick google shows that it isn't possible to have two python interpreters installed in the virtual environment. Since the plugin seems so popular I wondered how others were setting it up? Apologies if I've missed something major that explains this.
A bonus answer would also take into account that I am using docker and the docker image will install the python packages like this.
RUN pipenv install --system --deploy --ignore-pipfile
Many thanks in advance.
I am pretty sure it is just inaccurate description in the project docs, so you need either python 2.7 or python >=3.5 to be installed
In the end I didn't use django-celery-email. It's easy to send the emails generated by the django-allauth app without this package.
I used these resources -
https://github.com/anymail/django-anymail/issues/79
https://docs.djangoproject.com/en/2.2/topics/email/#defining-a-custom-email-backend
Basically you do this to get it working.
In settings.py define a CustomEmailBackend -
EMAIL_BACKEND = "users.backends.CustomEmailBackend"
In a backend.py file define the backend -
from django.core.mail.backends.base import BaseEmailBackend
from .tasks import async_send_messages
class CustomEmailBackend(BaseEmailBackend):
def send_messages(self, email_messages):
async_send_messages.delay(email_messages)
return len(email_messages)
And this is the task -
from django.core.mail import get_connection
from abstract_base_user.celery import app
#app.task(rety_backoff=True, serializer="pickle")
def async_send_messages(email_messages):
conn = get_connection(backend='anymail.backends.mailgun.EmailBackend')
conn.send_messages(email_messages)
The celery django app should be set up in the standard way as defined at https://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
And the celery settings in the settings.py need include the pickle content type -
CELERY_ACCEPT_CONTENT = ['json', 'pickle']
Obviously you need to include your anytime settings and broker settings too. But this should be enough to get anybody started.

ImportError: No module named comments django

I'm using os x , I tried to run the project that I installed from Github
https://github.com/cfpb/idea-box
but there is error says : ImportError: No module named comments
maybe I miss something but since I'm newbie in Django I can't figure it out
Django comments are deprecated in latest version. You can either install older django version (such as 1.5).
Or the better solution is to install comments from external repository like so:
pip install django-contrib-comments
and then change all imports like this:
from django.contrib.comments.models import Comment # old
from django_comments.models import Comment # new
Sources:
Django's docs
Another question

Import error web "no module named web"

I did an web application using web.py and after a while I realize that my python compiler was configure to use python2 instead of python3 (both are installed). With python2 my application was working but I got string in unicode so I try to execute my code using python3:
python3 mycode.py
But I get different kind of error, the lib urlparse was not found (this problem was cause by a new name in python3 which is urllib) but I got a problem with:
import web
The return error is:
ImportError: No module named 'web'
I can't figure out where the problem come from.
Web.py cannot work with python3, this is the linked to the gitub project.
https://github.com/webpy/webpy/issues/108
Maybe you have installed web in your python2 lib but you have none in python3 lib... Check it out

No module named middleware for django-bouncer

I'm using django-bouncer to make a waiting list in a Django 1.6 app. Unfortunately, when I add 'bouncer.middleware.MembersOnlyMiddleware' to my MIDDLEWARE_CLASSES as required, I get: "ImportError: No module named middleware." I tried going into the Django shell and typing "from bouncer.middleware import MembersOnlyMiddleware," but that received the same error.
What can I do to resolve this problem?
django-bouncer and bouncer are not the same package.
Try to install django-bouncer:
pip install django-bouncer

Installing Celery with Django

I'm trying to install celery with django and I'm get the following error:
from celery.task import sets
ImportError: cannot import name sets
How can I fix that?
Installing a newer version of celery might work. Or your install might not be complete.
But sets should be a part of celery.task.
Atleast, the latest docs indicate that this should be the case: http://ask.github.com/celery/reference/celery.task.sets.html
https://github.com/ask/celery/issues#issue/315
looks like an issue that has been reported.
You might be interested in these 2 pages of the #celery irc log
http://botland.oebfare.com/logger/celery/2011/3/4/2/
http://botland.oebfare.com/logger/celery/2011/3/4/3/