"errors":"errors":["detail":"您无权执行此操作。","code":&qu

Posted

技术标签:

【中文标题】"errors":"errors":["detail":"您无权执行此操作。","code":"permission_denied"]【英文标题】:"errors":"errors":["detail":"You do not have permission to perform this action.","code":"permission_denied"]"errors":"errors":["detail":"您无权执行此操作。","code":"permission_denied"] 【发布时间】:2022-01-22 19:31:44 【问题描述】:

当我在虚拟环境中运行python manage.py runserver 后访问http://127.0.0.1:8000/ 时,我收到此错误权限被拒绝 我的 Django 仍处于默认文件夹结构中,尚未更改 我尝试安装pip install django-cors-headers 并将以下所有内容添加到setting.py file 文件中

from corsheaders.middleware import CorsMiddleware
from corsheaders.middleware import CorsMiddleware
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True


ALLOWED_HOSTS = ['*']
CORS_ORIGIN_ALL_ALL =True
CORS_ALLOWED_ORIGINS = [
    "https://example.com",
    "https://sub.example.com",
    "http://localhost:8080",
    "http://127.0.0.1:9000",
]
CORS_ALLOWED_ORIGIN_REGEXES = [
    r"^https://\w+\.example\.com$",
]
CORS_URLS_REGEX = r"^/api/.*$"
CORS_ALLOW_METHODS = [
    "DELETE",
    "GET",
    "OPTIONS",
    "PATCH",
    "POST",
    "PUT",
]

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'corsheaders'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware'
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    "django.middleware.common.CommonMiddleware"
]

【问题讨论】:

你能显示 urls.py 和处理 / 路径的视图吗? 您在CORS_ALLOWD_ORIGINS 中设置了错误的端口。最后一行应该是"http://127.0.0.1:8000", 而不是9000 我也这样做了,但是没有用,我只是删除它并运行django-admin startproject mysite 【参考方案1】:

这只是 Django App 最初的样板项目(基本结构) 所以我已经删除它并再次运行django-admin startproject mysite

【讨论】:

以上是关于"errors":"errors":["detail":"您无权执行此操作。","code":&qu的主要内容,如果未能解决你的问题,请参考以下文章

验证测试用户 "error_type": "OAuthException", "code": 400, "error_messa

Spotify 白名单 URI 仍然返回 "error": "invalid_grant", "error_description": &

在创建 keycloak 用户时收到带有 "error":"unknown_error" 消息的 403 错误

如何从 Swift 中的 error.userInfo 获取 ["error"]["type"]?

收到错误 "errors":["message":"必须提供查询字符串。"]

Spring oauth2 中的 error="invalid_grant", error_description="Bad credentials"