小编Nip*_*arg的帖子

获取权限问题将经过身份验证的请求发送到OAuth2.0 Django休息Framwork

我已经将OAuth2.0与django-rest-framework集成在一起.当我将经过身份验证的请求发送到基于类的视图时,我得到了这个

{
    "detail": "You do not have permission to perform this action."
}
Run Code Online (Sandbox Code Playgroud)

settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    )
}
Run Code Online (Sandbox Code Playgroud)

views.py

    from rest_framework import permissions
    from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope
    class LogoutView(APIView):
        """
            This will help in logout of user.
        """
        authentication_classes = ()
        permission_classes = (permissions.IsAuthenticated, TokenHasReadWriteScope)

        def get(self, request):
            return Response({'s': 'd'})
Run Code Online (Sandbox Code Playgroud)

urls.py

from django.urls import path, re_path
from accounts.views import SignUpView, LoginView, LogoutView

urlpatterns = [
    path('signup/', SignUpView.as_view()),
    path('login/', LoginView.as_view()),
    path('logout/', LogoutView.as_view()), …
Run Code Online (Sandbox Code Playgroud)

python django django-rest-framework django-oauth

4
推荐指数
1
解决办法
307
查看次数

为什么创建一个简单的 Reqwest 客户端会出现恐慌?

当我运行这个时,我收到一个错误:

fn main() {
    let client = reqwest::Client::new();
}
Run Code Online (Sandbox Code Playgroud)
fn main() {
    let client = reqwest::Client::new();
}
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用构建器,但错误仍然存​​在。

fn main() {
    let mut client = reqwest::Client::builder(); // Panics here 
    match client.build() {
        Err(e) => {println!("{:?}", e);}
        _ => {}
    }
}
Run Code Online (Sandbox Code Playgroud)

这是此代码的完整堆栈回溯。

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:345:21
Run Code Online (Sandbox Code Playgroud)

rust reqwest

1
推荐指数
1
解决办法
818
查看次数