简体   繁体   English

Django Rest 框架:未提供身份验证凭据

[英]Django Rest Framework : Authentication credentials were not provided

Images in the current database have one piece of data.当前数据库中的图像有一条数据。

But, I am currently experiencing the following error但是,我目前遇到以下错误

"GET /images/all/ HTTP/1.1" 401 58" "detail": "Authentication credentials were not provided."

My Git Hub URL: https://github.com/Nomadcoders-Study/Nomadgram我的 Git Hub URL: https://github.com/Nomadcoders-Study/Nomadgram

Which part of the setup went wrong?设置的哪一部分出错了?

I saw your Github project settings.py file.我看到了你的 Github 项目 settings.py 文件。

This error is because you are using IsAuthenticated backend for all of your requests to Rest APIs.此错误是因为您对 Rest API 的所有请求都使用 IsAuthenticated 后端。 Also you setup jwt authorization system:您还设置了 jwt 授权系统:

REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
    'rest_framework.permissions.IsAuthenticated',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
    'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
}

So basically, if you want to create a request to any of your API endpoints, you should provide jwt token authorization header in it.所以基本上,如果您想创建对任何 API 端点的请求,您应该在其中提供 jwt 令牌授权 header。 like this for:像这样:

curl "<your api endpoint>" -H "Authorization: jwt <token_received>"

Also remember to setup and API to receive token from it, by providing username and password in serializer.还请记住通过在序列化程序中提供用户名和密码来设置和 API 以从中接收令牌。

try this in your settings file在你的设置文件中试试这个

settings.py设置.py

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
    'DEFAULT_AUTHENTICATION_CLASSES': ('rest_framework_simplejwt.authentication.JWTAuthentication',),


}

You can add it to your project Settings rest_framework configuration您可以将其添加到您的项目设置 rest_framework 配置

settings.py设置.py

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES'('rest_framework.authentication.BasicAuthentication', ),
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未提供Django Rest Framework身份验证凭据 - Django Rest Framework Authentication credentials were not provided Django Rest 框架 - 未提供身份验证凭据 - Django Rest Framework - Authentication credentials were not provided Django Rest Framework-使用渲染器时未提供身份验证凭据 - Django Rest Framework - Authentication credentials were not provided when using renderer django rest 框架中未提供错误身份验证凭据 - getting error Authentication credentials were not provided in django rest framework Python 请求与 Django Rest 框架 - “详细信息”:“未提供身份验证凭据” - Python Requests with Django Rest Framework - 'detail': 'Authentication credentials were not provided' Django Rest Framework JWT未提供身份验证凭据 - Authentication credentials were not provided with Django Rest Framework JWT Django Rest Framework JWT“未提供身份验证凭据。”} - Django Rest Framework JWT “Authentication credentials were not provided.”} Django Rest Framework {“detail”:“未提供身份验证凭据。”} - Django Rest Framework {“detail”:“Authentication credentials were not provided.”} Django Rest 框架 allauth 未提供身份验证凭据 - Django Rest Framework allauth Authentication credentials were not provided 未提供Angular + Django REST身份验证凭据 - Angular + Django REST Authentication credentials were not provided
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM