python - Django Rest Framework - Unicode error -
i using django rest framework django-oauth-toolkit, have used earlier , never have face issue.
i have followed per documentation of django-oauth-toolkit
on trying request access token:
curl -h post -d "grant_type=password&username=k@k.com&password=k&client_id=abc&client_secret=abc" http://127.0.0.1:8000/o/token/
i following stack trace:
[27/nov/2014 06:11:41] error [django.request:226] internal server error: /o/token/ traceback (most recent call last): file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/django/core/handlers/base.py", line 114, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/django/views/generic/base.py", line 69, in view return self.dispatch(request, *args, **kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/django/utils/decorators.py", line 29, in _wrapper return bound_func(*args, **kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 57, in wrapped_view return view_func(*args, **kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/django/utils/decorators.py", line 25, in bound_func return func(self, *args2, **kwargs2) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/braces/views/_forms.py", line 22, in dispatch return super(csrfexemptmixin, self).dispatch(*args, **kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/django/views/generic/base.py", line 87, in dispatch return handler(request, *args, **kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauth2_provider/views/base.py", line 154, in post url, headers, body, status = self.create_token_response(request) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauth2_provider/views/mixins.py", line 124, in create_token_response return core.create_token_response(request) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauth2_provider/oauth2_backends.py", line 106, in create_token_response headers) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/endpoints/base.py", line 61, in wrapper return f(endpoint, uri, *args, **kwargs) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/endpoints/token.py", line 85, in create_token_response request = request(uri, http_method=http_method, body=body, headers=headers) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/common.py", line 398, in __init__ self.headers = caseinsensitivedict(encode(headers or {})) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/common.py", line 394, in <lambda> encode = lambda x: to_unicode(x, encoding) if encoding else x file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/common.py", line 342, in to_unicode return dict(((to_unicode(k, encoding), to_unicode(v, encoding)) k, v in data)) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/common.py", line 342, in <genexpr> return dict(((to_unicode(k, encoding), to_unicode(v, encoding)) k, v in data)) file "/users/k/documents/personaldata/rock_env/lib/python2.7/site-packages/oauthlib/common.py", line 328, in to_unicode return unicode_type(data, encoding=encoding) unicodedecodeerror: 'utf8' codec can't decode byte 0xce in position 0: invalid continuation byte
also same code working on server not on local machine. on ubuntu server. local machine mac(yosemite).
any appreciated.
you may escape data per http://curl.haxx.se/docs/httpscripting.html#post
=> '@' should replaced %40
Comments
Post a Comment