用于谷歌应用程序引擎和Django的python调试器

时间:2021-08-27 23:51:03

I am having a problem that has baffled me for over a week. I have a project that is written in python with Django on Google App Engine. The project has a login page and when I run the application in Google App Engine or from the command line using dev_server.py c:\project, it works fine. When I try to run the application through a debugger like Wing or Pycharm, I cannot get past the login page. After trying to login, it takes me back to the login screen again. When I look at the logs, it shows a 302 (redirect) in the debugger but normally it shows a 200 (OK). Could someone explain why this would be happening?

我有个问题困扰了我一个多星期。我有一个项目是用python和Django在谷歌应用程序引擎上编写的。该项目有一个登录页面,当我在谷歌应用程序引擎或使用dev_server从命令行运行应用程序时。py c:\项目,它工作得很好。当我试图通过Wing或Pycharm等调试器运行应用程序时,我无法通过登录页面。在尝试登录之后,它会将我带回登录屏幕。当我查看日志时,它在调试器中显示了302(重定向),但通常它显示了200 (OK)。有人能解释一下为什么会这样吗?

Thanks -Dimitry

由于迪米特里•

2 个解决方案

#1


1  

This isn't really a great answer since I don't know much about Wing or Pycharm. But dev_appserver reroutes stdin and stdout to the WSGI handler. If you hit a breakpoint set by pdb.set_trace(), the breakpoint usually drops you to a shell that uses stdin/stdout, but with dev_appserver, you'll see the debugger shell piped to your HTTP, and there's no input available.

这并不是一个很好的答案,因为我不太了解翅膀或Pycharm。但是dev_appserver将stdin和stdout重新路由到WSGI处理程序。如果您碰到了由pdb.set_trace()设置的断点,那么这个断点通常会将您拖到使用stdin/stdout的shell中,但是对于dev_appserver,您将看到调试器shell通过管道传输到您的HTTP,并且没有可用的输入。

I'm not sure how Wing/Pycharm handle this. Pydev with eclipse works with dev_appserver, but that might be because of the GAE eclipse plugin.

我不知道温/皮斯卡姆怎么处理这件事。Pydev与eclipse协同dev_appserver工作,但这可能是因为GAE eclipse插件。

I find myself often embedding breakpoints in my code and debugging manually at the shell, mostly because it runs way faster than in the pydev debugger. I do this be rerouting stdin/stdout back to the terminal when I hit a breakpoint. http://eatdev.tumblr.com/post/12076034867/using-pdb-on-app-engine

我发现自己经常在代码中嵌入断点并在shell中手动调试,主要是因为它比pydev调试器运行得快。当我到达一个断点时,我将把stdin/stdout重新路由到终端。http://eatdev.tumblr.com/post/12076034867/using-pdb-on-app-engine

I'm on a linux environment. I did work with the GAE app launcher on Windows for a little bit, but not recently. I think I recall the app launcher hiding the original terminal that launches dev_appserver, so you might have to launch dev_appserver from the command prompt for this to work. I suspect you may need similar hacks if Wing or Pycharm use pdb underneath.

我在一个linux环境中。我曾在Windows上使用过GAE应用程序启动器,但不是最近。我记得应用程序启动器隐藏了启动dev_appserver的原始终端,因此您可能需要从命令提示符中启动dev_appserver才能使其工作。我猜你可能需要类似的技巧,如果翼或Pycharm使用pdb在下面。

#2


1  

After a week of racking my brain, I finally figured out the problem. The gaesessions code was the culprit. We put DEFAULT_LIFETIME = datetime.timedelta(hours=1) and originally it was DEFAULT_LIFETIME = datetime.timedelta(days=7). Not sure why running it through any debugger such as wing or pycharm would prevent the browser from getting a session. The interesting thing is the code change with hours=1 works fine on linux with wing debugger. Very Strange!

经过一个星期的绞尽脑汁,我终于解决了这个问题。代祷代码是罪魁祸首。我们将DEFAULT_LIFETIME = datetime.timedelta(hours=1)设置为DEFAULT_LIFETIME = datetime.timedelta(days=7)。不知道为什么通过任何调试器(如wing或pycharm)运行它会阻止浏览器获得会话。有趣的是,在使用wing调试器的linux上,小时=1的代码更改是可行的。非常奇怪!

#1


1  

This isn't really a great answer since I don't know much about Wing or Pycharm. But dev_appserver reroutes stdin and stdout to the WSGI handler. If you hit a breakpoint set by pdb.set_trace(), the breakpoint usually drops you to a shell that uses stdin/stdout, but with dev_appserver, you'll see the debugger shell piped to your HTTP, and there's no input available.

这并不是一个很好的答案,因为我不太了解翅膀或Pycharm。但是dev_appserver将stdin和stdout重新路由到WSGI处理程序。如果您碰到了由pdb.set_trace()设置的断点,那么这个断点通常会将您拖到使用stdin/stdout的shell中,但是对于dev_appserver,您将看到调试器shell通过管道传输到您的HTTP,并且没有可用的输入。

I'm not sure how Wing/Pycharm handle this. Pydev with eclipse works with dev_appserver, but that might be because of the GAE eclipse plugin.

我不知道温/皮斯卡姆怎么处理这件事。Pydev与eclipse协同dev_appserver工作,但这可能是因为GAE eclipse插件。

I find myself often embedding breakpoints in my code and debugging manually at the shell, mostly because it runs way faster than in the pydev debugger. I do this be rerouting stdin/stdout back to the terminal when I hit a breakpoint. http://eatdev.tumblr.com/post/12076034867/using-pdb-on-app-engine

我发现自己经常在代码中嵌入断点并在shell中手动调试,主要是因为它比pydev调试器运行得快。当我到达一个断点时,我将把stdin/stdout重新路由到终端。http://eatdev.tumblr.com/post/12076034867/using-pdb-on-app-engine

I'm on a linux environment. I did work with the GAE app launcher on Windows for a little bit, but not recently. I think I recall the app launcher hiding the original terminal that launches dev_appserver, so you might have to launch dev_appserver from the command prompt for this to work. I suspect you may need similar hacks if Wing or Pycharm use pdb underneath.

我在一个linux环境中。我曾在Windows上使用过GAE应用程序启动器,但不是最近。我记得应用程序启动器隐藏了启动dev_appserver的原始终端,因此您可能需要从命令提示符中启动dev_appserver才能使其工作。我猜你可能需要类似的技巧,如果翼或Pycharm使用pdb在下面。

#2


1  

After a week of racking my brain, I finally figured out the problem. The gaesessions code was the culprit. We put DEFAULT_LIFETIME = datetime.timedelta(hours=1) and originally it was DEFAULT_LIFETIME = datetime.timedelta(days=7). Not sure why running it through any debugger such as wing or pycharm would prevent the browser from getting a session. The interesting thing is the code change with hours=1 works fine on linux with wing debugger. Very Strange!

经过一个星期的绞尽脑汁,我终于解决了这个问题。代祷代码是罪魁祸首。我们将DEFAULT_LIFETIME = datetime.timedelta(hours=1)设置为DEFAULT_LIFETIME = datetime.timedelta(days=7)。不知道为什么通过任何调试器(如wing或pycharm)运行它会阻止浏览器获得会话。有趣的是,在使用wing调试器的linux上,小时=1的代码更改是可行的。非常奇怪!