简体   繁体   中英

Django Authentication credentials were not provided

So I'm using Http file to make GET request using rest_framework Authentication

here is the command I use:

GET localhost:8000/api-admin/products
Authorization: Token 5e2cf6ddc7a0ff8fe03e4749d788a423f6640443

When I use the browser and go to that link it works successfully but when I use HTTP file or Postman I get Authentication credentials were not provided. error

Also I added the code in settings file

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    )
}

我认为您必须在URL末尾添加尾随/。

The error was that I forgot to add TokenAuthentication in the authentication_classes

authentication_classes = (SessionAuthentication, BasicAuthentication, TokenAuthentication)

inside the API file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM