/graphql 处的递归错误。超出最大递归深度
Posted
技术标签:
【中文标题】/graphql 处的递归错误。超出最大递归深度【英文标题】:RecursionError at /graphql. maximum recursion depth exceeded 【发布时间】:2020-09-30 02:13:25 【问题描述】:问题定义:
我已阅读有关使用来自this official link 的graphene-jwt
包为我的项目添加JWT 身份验证的文章。根据教程中所说,应该对项目settings.py
文件进行一些更改:
-
首先应该安装软件包:
pip3 install django-graphql-jwt
-
将 AuthenticationMiddleware 添加到
MIDDLEWARE
变量。
MIDDLEWARE = [
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
]
-
添加 JSONWebTokenBackend 后端
AUTHENTICATION_BACKENDS
变量:
AUTHENTICATION_BACKENDS = [
'graphql_jwt.backends.JSONWebTokenBackend',
'django.contrib.auth.backends.ModelBackend',
]
-
将 JSONWebTokenMiddleware 添加到
GRAPEHENE
变量。
GRAPHENE =
'SCHEMA': 'apps.schema.schema.schema', # Where your Graphene schema lives
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
完成第 4 步后,对localhost:8000/graphql
的每个请求都有以下堆栈跟踪:
errorInternal Server Error: /graphql
Traceback (most recent call last):
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 62, in view
self = cls(**initkwargs)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphene_django/views.py", line 78, in __init__
schema = graphene_settings.SCHEMA
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphene_django/settings.py", line 116, in __getattr__
val = perform_import(val, attr)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphene_django/settings.py", line 55, in perform_import
return import_from_string(val, setting_name)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphene_django/settings.py", line 69, in import_from_string
module = importlib.import_module(module_path)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/mostafa/Desktop/Work/OOD_Project/back/transportation/apps/schema/schema.py", line 2, in <module>
import graphql_jwt
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphql_jwt/__init__.py", line 1, in <module>
from . import relay
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphql_jwt/relay.py", line 3, in <module>
from . import mixins
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphql_jwt/mixins.py", line 10, in <module>
from . import exceptions, settings
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/graphql_jwt/settings.py", line 26, in <module>
JWT_SECRET_KEY = env('JWT_SECRET_KEY', default=settings.SECRET_KEY)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/environ/environ.py", line 123, in __call__
return self.get_value(var, cast=cast, default=default, parse_default=parse_default)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/environ/environ.py", line 284, in get_value
value = self.get_value(value, cast=cast, default=default)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/environ/environ.py", line 284, in get_value
value = self.get_value(value, cast=cast, default=default)
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/environ/environ.py", line 284, in get_value
value = self.get_value(value, cast=cast, default=default)
[Previous line repeated 866 more times]
File "/home/mostafa/Desktop/Work/OOD_Project/back/venv/lib/python3.6/site-packages/environ/environ.py", line 273, in get_value
value = self.ENVIRON[var]
File "/usr/lib/python3.6/os.py", line 666, in __getitem__
value = self._data[self.encodekey(key)]
RecursionError: maximum recursion depth exceeded:
项目结构:
├── apps
│ └── orders
│ ├── ... other-files
│ ├── schema.py
│ └── schema
│ └── schema.py
│ └── users
│ ├── ... other-files
│ └── schema.py
截图:
我不知道这是一个错误还是我的错。 (在添加上述配置之前,API 运行良好,并且已经检查了很多次)我在互联网上搜索过,但没有找到我的问题的正确答案。如果有人可以帮助我,我将不胜感激。
PS1: 与我相关的最著名的问题是this one,主要讲的是python中的最大递归深度误差。但是我在这里无法理解此错误的原因。
PS2:我还在 settings.py 中添加了以下几行,但它仍然不起作用!
import sys
sys.setrecursionlimit(10000)
【问题讨论】:
我不知道 graphql,但是当我不小心自己添加了应用程序的 url 时遇到了相同类型的错误。因此,请检查您的应用程序和项目的 urls 文件,它可能会有所帮助。 @Sheraram_Prajapat 在我执行第四步之前它就起作用了。 那么对不起兄弟,我帮不了你我对graphql一无所知 【参考方案1】:看看这个问题: https://github.com/joke2k/django-environ/issues/60
我认为您的密钥以 $ 开头,这就是问题所在。
【讨论】:
嗨,Kaftar,对不起,这些天我还是很忙。我会在 3 天内看看它。非常感谢。以上是关于/graphql 处的递归错误。超出最大递归深度的主要内容,如果未能解决你的问题,请参考以下文章