0

I am trying to implement JSON wen token in Django. I have been following tutorial from this source I have installed and configured all the necessary requirements.

To obtain user's token, here is the curl example:

$ curl --request POST \
      --url http://localhost:8000/jwt-auth/ \
      --header 'content-type: application/json' \
      --data '{"username": "myusername", "password": "mypass"}'

      {"token": "YOUR_JWT_TOKEN"}

Here is my code for making call

import requests

item = { "username": "admin", "password": "admin"}
resp1 = requests.post("http://localhost:8000/auth-jwt/", 
               data=json.dumps(item),
               headers={
                       "Content-Type":"application/json",
                       "Accept": "application/json"
                      }
 )
print (resp1.status_code)
#print (resp1.content)
content = json.loads(resp1.content)
print(content)
#print(content['status'])

My issues:

When I run the above code, it returns error

non field error: unable to login with provided credentials

What does this mean. which table do I have to create to use their credentials. Currently I have users nancy on auth_user table.

Consequently, a similar issue has been resolved here but I cannot get it to work.

What does the error mean, and what is the next step in solving the problem?

halfer
  • 19,824
  • 17
  • 99
  • 186
Nancy Moore
  • 2,322
  • 2
  • 21
  • 38

1 Answers1

0

I found out my problem. I need to create a superuser account as per

$ python manage.py createsuperuser

so running this syntax squentially at command prompts solves my problem.

 python manage.py makemigrations
 python manage.py migrate
 python manage.py createsuperuser
 python manage.py runserver
Nancy Moore
  • 2,322
  • 2
  • 21
  • 38