尝试请求OAuth access_token时,我得到:TypeError:encode()参数1必须为字符串,而不是None

德拉兹科夫斯基

我已经在Django和Django Rest Framework中编写了一个应用程序,并使用Django OAuth Toolkit添加了OAuth身份验证。我一直在遵循Django OAuth Toolkit入门指南

现在,当我尝试使用以下命令请求access_token时:

curl -X POST -d "grant_type=password&username=myuser&password=mypass" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/ 

我得到如下的追溯:

Dispatching grant_type password request to <oauthlib.oauth2.rfc6749.grant_types.resource_owner_password_credentials.ResourceOwnerPasswordCredentialsGrant object at 0x7f80420bbb90>.
Authenticating client, <oauthlib.common.Request object at 0x7f804332bcd0>.
Internal Server Error: /o/token/
Traceback (most recent call last):
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/braces/views/_forms.py", line 22, in dispatch
    return super(CsrfExemptMixin, self).dispatch(*args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 34, in _wrapper
    return bound_func(*args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
    return view(request, *args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/django/utils/decorators.py", line 30, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauth2_provider/views/base.py", line 170, in post
    url, headers, body, status = self.create_token_response(request)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauth2_provider/views/mixins.py", line 124, in create_token_response
    return core.create_token_response(request)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauth2_provider/oauth2_backends.py", line 138, in create_token_response
    headers, extra_credentials)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/endpoints/base.py", line 61, in wrapper
    return f(endpoint, uri, *args, **kwargs)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/endpoints/token.py", line 93, in create_token_response
    request, self.default_token_type)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py", line 92, in create_token_response
    if not self.request_validator.authenticate_client(request):
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauth2_provider/oauth2_validators.py", line 179, in authenticate_client
    authenticated = self._authenticate_basic_auth(request)
  File "/home/user/Projects/venv/lib/python2.7/site-packages/oauth2_provider/oauth2_validators.py", line 67, in _authenticate_basic_auth
    auth_string = auth_string.encode(encoding)
TypeError: encode() argument 1 must be string, not None

我正在使用Django版本1.8.5,Django REST框架版本3.3.2和Django OAuth Toolkit版本0.10.0。

我找到了导致该问题的代码:

def _authenticate_basic_auth(self, request):
    """
    Authenticates with HTTP Basic Auth.

    Note: as stated in rfc:`2.3.1`, client_id and client_secret must be encoded with
    "application/x-www-form-urlencoded" encoding algorithm.
    """
    auth_string = self._extract_basic_auth(request)
    if not auth_string:
        return False

    try:
        encoding = request.encoding
    except AttributeError:
        encoding = 'utf-8'

    # Encode auth_string to bytes. This is needed for python3.2 compatibility
    # because b64decode function only supports bytes type in input.
    if isinstance(auth_string, six.string_types):
        auth_string = auth_string.encode(encoding)
    [...]

但是不知道为什么encoding价值是None如果我的项目中的任何文件有用,我将提供它们。

德肯

修复正在等待中:https : //github.com/evonove/django-oauth-toolkit/pull/341

这样看起来发生在所述请求的炭编码是一样的django.conf.settings.DEFAULT_CHARSET,这将导致request.encodingNone如记录

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

尝试为Coinbase设置解耦的oauth,令牌请求的代码失败

来自分类Dev

OAuth access_token请求->禁止

来自分类Dev

OAuth access_token请求->禁止

来自分类Dev

当我尝试使用BeautifulSoup解析HTML页面时出现“ TypeError:字符串索引必须为整数”错误

来自分类Dev

TypeError:尝试打印href时,字符串索引必须为整数

来自分类Dev

获取TypeError:type()参数1必须为字符串,而不是None

来自分类Dev

获取TypeError:type()参数1必须为字符串,而不是None

来自分类Dev

当我尝试获取access_token时,Python-social-auth管道返回TypeError

来自分类Dev

尝试使用OAuth访问SmartCloud时出错

来自分类Dev

使用数组参数签署OAuth请求

来自分类Dev

如何使用Oauth请求提交和处理请求参数?

来自分类Dev

python TypeError:参数1必须是字符串或只读字符缓冲区,而不是None

来自分类Dev

TypeError:参数1必须是字符串或只读字符缓冲区,而不是None

来自分类Dev

使用Python请求模块时尝试/例外

来自分类Dev

尝试使用“请求”模块时导入错误

来自分类Dev

; [HPM]尝试代理请求时发生错误

来自分类Dev

尝试按别名过滤时请求错误

来自分类Dev

尝试发送 PUT 请求时出现 ConnectionResetError

来自分类Dev

OAuth2.0使用cURL安全性请求access_token

来自分类Dev

当我尝试添加拆分后的字符串时,为什么会得到空字符串?

来自分类Dev

在尝试读取时得到:“无法处理内核分页请求”

来自分类Dev

如何通过OAUTH请求user_access_token而不是app_access_token

来自分类Dev

为什么我得到415尝试发布字符串?

来自分类Dev

angularJS:http请求配置url必须为字符串

来自分类Dev

XAMPP - “错误请求”当我尝试访问 https 端口时

来自分类Dev

尝试连接到Google API的Google Oauth时无效的JWT

来自分类Dev

当我尝试Date.parse日期时,如何传递不是日期的字符串?

来自分类Dev

尝试发送POST请求并获取json数据,但得到400

来自分类Dev

尝试使用MockMvc进行测试而不上传任何文件时,“当前请求不是多部分请求”

Related 相关文章

  1. 1

    尝试为Coinbase设置解耦的oauth,令牌请求的代码失败

  2. 2

    OAuth access_token请求->禁止

  3. 3

    OAuth access_token请求->禁止

  4. 4

    当我尝试使用BeautifulSoup解析HTML页面时出现“ TypeError:字符串索引必须为整数”错误

  5. 5

    TypeError:尝试打印href时,字符串索引必须为整数

  6. 6

    获取TypeError:type()参数1必须为字符串,而不是None

  7. 7

    获取TypeError:type()参数1必须为字符串,而不是None

  8. 8

    当我尝试获取access_token时,Python-social-auth管道返回TypeError

  9. 9

    尝试使用OAuth访问SmartCloud时出错

  10. 10

    使用数组参数签署OAuth请求

  11. 11

    如何使用Oauth请求提交和处理请求参数?

  12. 12

    python TypeError:参数1必须是字符串或只读字符缓冲区,而不是None

  13. 13

    TypeError:参数1必须是字符串或只读字符缓冲区,而不是None

  14. 14

    使用Python请求模块时尝试/例外

  15. 15

    尝试使用“请求”模块时导入错误

  16. 16

    ; [HPM]尝试代理请求时发生错误

  17. 17

    尝试按别名过滤时请求错误

  18. 18

    尝试发送 PUT 请求时出现 ConnectionResetError

  19. 19

    OAuth2.0使用cURL安全性请求access_token

  20. 20

    当我尝试添加拆分后的字符串时,为什么会得到空字符串?

  21. 21

    在尝试读取时得到:“无法处理内核分页请求”

  22. 22

    如何通过OAUTH请求user_access_token而不是app_access_token

  23. 23

    为什么我得到415尝试发布字符串?

  24. 24

    angularJS:http请求配置url必须为字符串

  25. 25

    XAMPP - “错误请求”当我尝试访问 https 端口时

  26. 26

    尝试连接到Google API的Google Oauth时无效的JWT

  27. 27

    当我尝试Date.parse日期时,如何传递不是日期的字符串?

  28. 28

    尝试发送POST请求并获取json数据,但得到400

  29. 29

    尝试使用MockMvc进行测试而不上传任何文件时,“当前请求不是多部分请求”

热门标签

归档