I'm following the graphql python tutorial at https://www.howtographql.com/graphql-python/4-authentication/. It worked fine for the first 3 sections, but in the Authentication section I've run into this problem.
I am learning python, don't know Django or graphql, so it's a lot to digest all at once, but it was going ok until now. Also not sure what relevant bits to include here.
I followed all the instructions. When I go to my local project site at localhost:8000/graphql/
, I get
TypeError at /graphql/
__init__() missing 1 required positional argument: 'get_response'
Here is the relevant snippet of my settings.py:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]
GRAPHENE = {
'SCHEMA': 'hackernews.schema.schema',
'MIDDLEWARE': ['graphql_jwt.middleware.JSONWebTokenMiddleware', ],
}
AUTHENTICATION_BACKENDS = [
'graphql_jwt.backends.JSONWebTokenBackend',
'django.contrib.auth.backends.ModelBackend',
]
I also did import graphql_jwt in my main schema.py
Here is some kind of stack trace
Environment:
Request Method: GET
Request URL: http://localhost:8000/graphql/
Django Version: 2.1.4
Python Version: 3.7.4
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'graphene_django',
'links']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware']
Traceback:
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\django\core\handlers\exception.py" in inner
34. response = get_response(request)
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = self.process_exception_by_middleware(e, request)
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\django\core\handlers\base.py" in _get_response
124. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
54. return view_func(*args, **kwargs)
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\django\views\generic\base.py" in view
62. self = cls(**initkwargs)
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\graphene_django\views.py" in __init__
88. self.middleware = list(instantiate_middleware(middleware))
File "C:\Users\e79909\projects\python\graphql-python\venv\lib\site-packages\graphene_django\views.py" in instantiate_middleware
48. yield middleware()
Exception Type: TypeError at /graphql/
Exception Value: __init__() missing 1 required positional argument: 'get_response'
Ok, I just found it.
GRAPHENE = {
'SCHEMA': 'hackernews.schema.schema',
'MIDDLEWARES': ['graphql_jwt.middleware.JSONWebTokenMiddleware'],
}
Notice the S
. It needs to be 'MIDDLEWARES'
, not 'MIDDLEWARE'
.
Found the solution on this GitHub issue
Also, according to this comment on the same issue, you should add 'graphql_jwt.middleware.JSONWebTokenMiddleware'
to the MIDDLEWARE
list (the one with all the Django middleware).
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'graphql_jwt.middleware.JSONWebTokenMiddleware', ### <---Add this line
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With