2
votes

With the django rest framework I was using django-rest-framework-simplejwt from here.

According to the guideline given, my settings.py REST_FRAMERWORK should look like:

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
    ],
}

Now when I call the api /api/token/ with the help of CURL like this:

curl -X POST -H "Content-Type: application/json" -d '{"username": "aami", "password": "ooma"}' http://127.0.0.1:8000/api/token/

I get the following error:

curl -X POST -H "Content-Type: application/json" -d '{"username": "aami", "password": "ooma"}' http://127.0.0.1:8000/api/token/

And the server side the log is:

Bad Request: /api/token/ [12/Apr/2019 15:01:02] "POST /api/token/ HTTP/1.1" 400 75

I followed what the guidelines mentioned but I still can't figure out what's wrong.

1
If the error is no active account with the given credentials, it seems you are not passing the correct username and password, or the username does not exists.afonso
How did you create your users ? Can you show the piece of code ?Overdrivr

1 Answers

3
votes

This was happening to me. I realized I had created my users with

User.objects.create(username="xxx", password="yyy")

But in Django a special create_user method needs to be used. I deleted the user and changed to

User.objects.create_user(username="xxx", password="yyy")

and it worked.