Django 如何追溯调用完成的位置
Django How can I trace back where this call is done
自从我创建了一个新项目(Django 2.2 和 Python 3.7)以来,我每隔 60 秒就会定期打印此错误。
Not Found: /graphql
[24/Sep/2019 13:23:50] "GET /graphql HTTP/1.1" 404 4216
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53701)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 720, in __init__
self.handle()
File "/Users/robertofernandez/KMH/flowlemon_backen/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 171, in handle
self.handle_one_request()
File "/Users/robertofernandez/KMH/flowlemon_backen/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 179, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
我认为这个错误是由我安装的某些依赖项引起的(我没有任何视图或 URL 调用 graphql 并且我在我的项目中根本没有使用 graphql),但我是无法检测导致问题的软件包。
requirements.txt
attrs==19.1.0
certifi==2019.6.16
chardet==3.0.4
coreapi==2.3.3
coreschema==0.0.4
defusedxml==0.6.0
Django==2.2.4
django-braces==1.13.0
django-cors-headers==3.1.0
django-extensions==2.2.1
django-filter==2.2.0
django-oauth-toolkit==1.2.0
django-rest-framework-social-oauth2==1.1.0
djangorestframework==3.10.2
drf-yasg==1.16.1
idna==2.8
inflection==0.3.1
itypes==1.1.0
Jinja2==2.10.1
loguru==0.3.2
MarkupSafe==1.1.1
oauthlib==3.1.0
packaging==19.1
PyJWT==1.7.1
pyparsing==2.4.2
python-decouple==3.1
python3-openid==3.1.0
pytz==2019.2
requests==2.22.0
requests-oauthlib==1.2.0
ruamel.yaml==0.16.5
ruamel.yaml.clib==0.1.2
six==1.12.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
sqlparse==0.3.0
uritemplate==3.0.0
urllib3==1.25.3
知道如何追踪这个吗?
我的直觉是导致此错误的是前端包,因为 Django 包通常不需要向 Django 服务器发出 HTTP 请求。此外,它定期发生的事实表明客户端轮询。例如,也许您有 Apollo 客户端?
要具体回答您的问题,您可以在 /graphql
添加路由,然后检查请求的客户端和推荐人。
1) 使用到调试视图的临时路由更新 urls.py
urlpatterns = [
...
path('graphql', my_debug_view),
]
2) 使用 print
添加调试视图以在 runserver 控制台上显示请求信息
from django.http import HttpResponse
def my_debug_review(request):
print(request.META)
return HttpResponse("")
现在,您将看到有关请求的信息,而不是每 60 秒出现 404 错误。
完成后,不要忘记删除这些更改。
自从我创建了一个新项目(Django 2.2 和 Python 3.7)以来,我每隔 60 秒就会定期打印此错误。
Not Found: /graphql
[24/Sep/2019 13:23:50] "GET /graphql HTTP/1.1" 404 4216
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53701)
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 650, in process_request_thread
self.finish_request(request, client_address)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socketserver.py", line 720, in __init__
self.handle()
File "/Users/robertofernandez/KMH/flowlemon_backen/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 171, in handle
self.handle_one_request()
File "/Users/robertofernandez/KMH/flowlemon_backen/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 179, in handle_one_request
self.raw_requestline = self.rfile.readline(65537)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [Errno 54] Connection reset by peer
我认为这个错误是由我安装的某些依赖项引起的(我没有任何视图或 URL 调用 graphql 并且我在我的项目中根本没有使用 graphql),但我是无法检测导致问题的软件包。
requirements.txt
attrs==19.1.0
certifi==2019.6.16
chardet==3.0.4
coreapi==2.3.3
coreschema==0.0.4
defusedxml==0.6.0
Django==2.2.4
django-braces==1.13.0
django-cors-headers==3.1.0
django-extensions==2.2.1
django-filter==2.2.0
django-oauth-toolkit==1.2.0
django-rest-framework-social-oauth2==1.1.0
djangorestframework==3.10.2
drf-yasg==1.16.1
idna==2.8
inflection==0.3.1
itypes==1.1.0
Jinja2==2.10.1
loguru==0.3.2
MarkupSafe==1.1.1
oauthlib==3.1.0
packaging==19.1
PyJWT==1.7.1
pyparsing==2.4.2
python-decouple==3.1
python3-openid==3.1.0
pytz==2019.2
requests==2.22.0
requests-oauthlib==1.2.0
ruamel.yaml==0.16.5
ruamel.yaml.clib==0.1.2
six==1.12.0
social-auth-app-django==3.1.0
social-auth-core==3.2.0
sqlparse==0.3.0
uritemplate==3.0.0
urllib3==1.25.3
知道如何追踪这个吗?
我的直觉是导致此错误的是前端包,因为 Django 包通常不需要向 Django 服务器发出 HTTP 请求。此外,它定期发生的事实表明客户端轮询。例如,也许您有 Apollo 客户端?
要具体回答您的问题,您可以在 /graphql
添加路由,然后检查请求的客户端和推荐人。
1) 使用到调试视图的临时路由更新 urls.py
urlpatterns = [
...
path('graphql', my_debug_view),
]
2) 使用 print
from django.http import HttpResponse
def my_debug_review(request):
print(request.META)
return HttpResponse("")
现在,您将看到有关请求的信息,而不是每 60 秒出现 404 错误。
完成后,不要忘记删除这些更改。