[英]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.