2

我正在尝试设置令牌身份验证,但是当我尝试获取令牌时,出现此错误。端点是'/o/token/'。当我发布错误的 client_id 或错误的 grant_type 时,我会收到我期望的响应:

{
    "error": "invalid_client"
}

或者

{
    "error": "unsupported_grant_type"
}

但是在发送实际数据(grant_type、client_id、username、password)时,它会崩溃:

Internal Server Error: /o/token/
Traceback (most recent call last):
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/views/base.py", line 260, in post
    url, headers, body, status = self.create_token_response(request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/views/mixins.py", line 124, in create_token_response
    return core.create_token_response(request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/oauth2_backends.py", line 145, in create_token_response
    headers, extra_credentials)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/endpoints/base.py", line 116, in wrapper
    return f(endpoint, uri, *args, **kwargs)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/endpoints/token.py", line 119, in create_token_response
    request, self.default_token_type)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py", line 101, in create_token_response
    self.validate_token_request(request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py", line 184, in validate_token_request
    request.password, request.client, request):
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/oauth2_validators.py", line 611, in validate_user
    u = authenticate(request, username=username, password=password)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 72, in authenticate
    user = backend.authenticate(request, **credentials)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/backends.py", line 17, in authenticate
    valid, r = OAuthLibCore.verify_request(request, scopes=[])
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/oauth2_backends.py", line 172, in verify_request
    uri, http_method, body, headers = self._extract_params(request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/oauth2_backends.py", line 58, in _extract_params
    uri = self._get_escaped_full_path(request)
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauth2_provider/oauth2_backends.py", line 34, in _get_escaped_full_path
    parsed = list(urlparse(request.get_full_path()))
  File "/home/ben/.local/share/virtualenvs/riven-Lpl_ShSG/lib/python3.7/site-packages/oauthlib/common.py", line 436, in __getattr__
    raise AttributeError(name)
AttributeError: get_full_path
[12/Mar/2020 07:51:30] "POST /o/token/ HTTP/1.1" 500 177519

有时 token.py 会创建一个没有属性“get_full_path”的“oauthlib.Request”。有没有人遇到过同样的问题,或者可能知道是什么原因造成的?我的想法用完了:(

  • 蟒蛇 3.7
  • Django 3.0.4
  • djangorestframework 3.11.0
  • django-oauth-toolkit 1.3.0
  • oauthlib 3.1.0
4

0 回答 0