我有一个与docker一起部署的Django项目。我想用Python Remote Debug
调试项目。这就是我根据https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html
然后我启动调试器,它说:
Use the following code to connect to the debugger:
import pydevd_pycharm
pydevd_pycharm.settrace('0.0.0.0', port=3000, stdoutToServer=True, stderrToServer=True)
Waiting for process connection...
然后,我将代码复制到__main__
中的manage.py
顺便说一句。将上述代码放到views
上,而不是manage.py dint帮助
接下来我由docker用docker-compose up -d proj
命令启动
一段时间后,我从容器中看到日志,上面写着:
Could not connect to localhost: 3000
NoneType: None
Traceback (most recent call last):
File "/usr/local/lib/python3.6/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 93, in sentry_patched_wsgi_handler
environ, start_response
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/wsgi.py", line 69, in __call__
rv = self.app(environ, start_response)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 92, in <lambda>
return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 157, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/sentry_sdk/integrations/django/__init__.py", line 112, in sentry_patched_get_response
return old_get_response(self, request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in get_response
response = self._middleware_chain(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
response = self.get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/app/xwing/middleware.py", line 21, in middleware
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 116, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
response = handler(request, *args, **kwargs)
File "/app/cards/views.py", line 52, in version
return Response({'version': get_newest_version()})
File "/app/cards/queries.py", line 76, in get_newest_version
pydevd_pycharm.settrace('localhost', port=8080, stdoutToServer=True, stderrToServer=True)
File "/usr/local/lib/python3.6/site-packages/pydevd.py", line 1282, in settrace
stop_at_frame,
File "/usr/local/lib/python3.6/site-packages/pydevd.py", line 1327, in _locked_settrace
debugger.connect(host, port) # Note: connect can raise error.
File "/usr/local/lib/python3.6/site-packages/pydevd.py", line 364, in connect
s = start_client(host, port)
File "/usr/local/lib/python3.6/site-packages/_pydevd_bundle/pydevd_comm.py", line 568, in start_client
sys.exit(1) #TODO: is it safe?
SystemExit: 1
到目前为止,我尝试在其他端口(例如0.0.0.0:8000、localhost:8000)上运行调试服务器。但这没有帮助。我参加了另一个项目,确实需要docker才能工作,并且一切正常。似乎docker有问题。有任何想法吗?我不知道为什么我不工作。
答案 0 :(得分:1)
我从来没有做过,但是看起来'0.0.0.0'部分是运行Pycharm的机器的地址。
您必须设置机器的IP。在网络模式“主机”下运行容器也可能会成功(因为0.0.0.0是指容器内部)
也许您也觉得有用: