Json-API in combination of django-rest-framework-jwt
See original GitHub issueIn my unit tests, when I do a post, I get the following error:
======================================================================
ERROR: test_get_one_vehicletype_in_french (masterdata.tests.VehicleTypeTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/src/app/cardispo2/masterdata/tests.py", line 206, in setUp
super(VehicleTypeTest, self).setUp()
File "/usr/src/app/cardispo2/cardispo2/test_helper.py", line 83, in setUp
self.client.login(username='tester', password='blabla')
File "/usr/src/app/cardispo2/cardispo2/test_helper.py", line 57, in login
response = self.post('/api/v1/auth/login', {"username": username, "password": password})
File "/usr/local/lib/python3.4/site-packages/rest_framework/test.py", line 168, in post
path, data=data, format=format, content_type=content_type, **extra)
File "/usr/local/lib/python3.4/site-packages/rest_framework/test.py", line 89, in post
data, content_type = self._encode_data(data, format, content_type)
File "/usr/local/lib/python3.4/site-packages/rest_framework/test.py", line 64, in _encode_data
ret = renderer.render(data)
File "/usr/local/lib/python3.4/site-packages/rest_framework_json_api/renderers.py", line 36, in render
resource_name = utils.get_resource_name(renderer_context)
File "/usr/local/lib/python3.4/site-packages/rest_framework_json_api/utils.py", line 32, in get_resource_name
view = context.get('view')
AttributeError: 'NoneType' object has no attribute 'get'
If you look at the last three steps in the trace, there is ret = renderer.render(data)
which calls rest_framework_json_api.JSONRenderer.render
without a renderer_context
argument. It then passes None (default value) to rest_framework_json_api.utils.get_resource_name
where it tries to call view = context.get('view')
on None… which of course can’t work.
My DRF settings:
REST_FRAMEWORK = {
'PAGINATE_BY': 30,
'PAGINATE_BY_PARAM': 'page_size',
'MAX_PAGINATE_BY': 100,
#'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',
'DEFAULT_PAGINATION_CLASS':
'rest_framework_json_api.pagination.PageNumberPagination',
'DEFAULT_PARSER_CLASSES': (
'rest_framework_json_api.parsers.JSONParser',
'rest_framework.parsers.MultiPartParser',
),
'DEFAULT_RENDERER_CLASSES': (
'rest_framework_json_api.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
),
'TEST_REQUEST_RENDERER_CLASSES': (
'rest_framework_json_api.renderers.JSONRenderer',
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
'EXCEPTION_HANDLER': 'cardispo2.exceptions.custom_exception_handler',
'TEST_REQUEST_DEFAULT_FORMAT': 'json'
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
1.6.0 - Getting error "too many values to unpack" #127 - GitHub
Mind that I'm using https://github.com/django-json-api/django-rest-framework-json-api, not sure if it has to do with the error.
Read more >JSON:API with django-rest-framework-json-api and JWT
Any possible way of single sign on service with django rest framework? 19 · How to get username from Django Rest Framework JWT...
Read more >Django REST framework JWT - GitHub Pages
This package provides JSON Web Token Authentication support for Django REST framework. If you want to know more about JWT, check out the...
Read more >Usage - Django REST framework JSON:API - Read the Docs
Many features of the JSON:API format standard have been implemented using Mixin ... If you set the resource_name on a combination of model,...
Read more >Django Rest API with JSON web token(JWT) authentication.
We will be using djangorestframework-jwt for authenticating the user using. Open the shell and fire the below command with virtual env ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I have a content negotiation problem, since the JWT data should be plain json and the api data jsonapi.
Depending on the order of of the parsers and renderers in settings.py (I currently have both, rest_framework.renderers/parsers and rest_framework_json_api.renderers/parsers) and accept headers I can either get
working.
Since you’re saying “I prefer to submit and retrieve jwt related stuff in the application/json format.” I suspect you know the correct combination of configuration and Accept headers (maybe content-type too?) 😃
Sorry for being a bit off topic here.
Sorry, yes!