WebFaction
Community site: login faq

During development, I'm wanting to switch Werkzeug debug mode on and off, using Flask + Werkzeug framework, as a WebFaction mod_wsgi application. On my localhost, setting app.debug = True gives me the full Werkzeug traceback on an error, but with the mod_wsgi setup, when I set application.debug = True, I still get the standard "Internal Server Error".

What do I need to do to switch into debug mode?

asked 24 Oct '10, 04:41

RobC
1112
accept rate: 0%


You should first setup a custom app listening on port.

Then start your application in debug mode to listen on that port in a screen or you could add the relevant command to your crontab.

You could then point your domain to the custom app and thus expose the debugger to your intended audience.

But please note you shoudl restrict access to this debugger to trusted users.

If we find unsolicited access and misuse it will constitute a violation of our AUP(http://www.webfaction.com/legal/aup)

Hope that helps!

permanent link

answered 25 Oct '10, 04:57

neeravk
1.5k3412
accept rate: 41%

That sounds like a good way around the problem. I'll give that a go.

(25 Oct '10, 12:10) RobC

Did you try restarting the Apache server after modifying your app settings?

permanent link

answered 24 Oct '10, 04:47

tie
1.4k13
accept rate: 44%

Yes, restarted many times. Indeed, it was the restarting and debug switching that I was trying to implement for Flask, like this post for Django on WebFaction: http://www.owaislone.org/blog/2009/dec/python-django-apache-webfaction/. But there must be something that overrides my debug setting.

(24 Oct '10, 07:27) RobC

I see you have multiple Flask/mod_wsgi apps set up in your account. Which of these is showing the problem?

(24 Oct '10, 07:50) David L ♦♦

The app I'm working on is aer_gen, where my index.wsgi contains the one line:

from migrator.aer.server import app as application

A print statement shows that application.debug is True at that point, but no traceback appears on an error.

(24 Oct '10, 10:09) RobC

Ah. I believe you need to run mod_wsgi in daemon mode with a single process in order to use the debugger.

I'm pulling that from memory, though, so I could be wrong about the exact details.

Could you try running like that and see if it helps?

(24 Oct '10, 10:18) David L ♦♦

OK, I think I've tried that now: in the Apache configuration file, I changed the line to

WSGIDaemonProcess aer_gen processes=1 threads=5 or WSGIDaemonProcess aer_gen processes=1 threads=1

The pages work fine, and then I insert an "assert 0" when I still get a 500 Internal Server Error rather than a traceback.

(24 Oct '10, 14:32) RobC

What does the error log on the server say? A 500 error will be placed in the error log, ~/logs/user/error_appname.log.

permanent link

answered 24 Oct '10, 14:57

johns
5.3k312
accept rate: 23%

edited 24 Oct '10, 14:58

When I put in my debug line assert 0, I get the desired traceback in the error log, but not interactively in the web page:

[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1] mod_wsgi (pid=28768): Exception occurred processing WSGI script '/home/username/webapps/aer_gen/htdocs/index.wsgi'.
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]   File "/home/username/lib/python2.6/Flask-0.6-py2.6.egg/flask/app.py", line 874, in __call__
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]     return self.wsgi_app(environ, start_response)
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]   File "/home/username/lib/python2.6/Flask-0.6-py2.6.egg/flask/app.py", line 864, in wsgi_app
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]     response = self.make_response(self.handle_exception(e))
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]   File "/home/username/lib/python2.6/Flask-0.6-py2.6.egg/flask/app.py", line 861, in wsgi_app
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]     rv = self.dispatch_request()
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]   File "/home/username/lib/python2.6/Flask-0.6-py2.6.egg/flask/app.py", line 696, in dispatch_request
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]     return self.view_functions[rule.endpoint](**req.view_args)
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]   File "/home/username/projects/migrator/aer/server.py", line 145, in node_by_name
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1]     assert 0
[Sun Oct 24 16:48:13 2010] [error] [client 127.0.0.1] AssertionError
permanent link

answered 24 Oct '10, 17:12

RobC
1112
accept rate: 0%

According to Flask's documentation this is not something you should do in an production environment and will not work,

http://flask.pocoo.org/docs/quickstart/#debug-mode

permanent link

answered 24 Oct '10, 20:03

johns
5.3k312
accept rate: 23%

I realise that an interactive debugger in a production setup is a bad idea. What I'm trying to do is to use my WebFaction account to give distributed developers access to the server, beyond what I can do with app.run(debug=True) from my laptop. They will be testing and giving feedback, with no public access.

Flask docs: "the interactive debugger does not work in forking environments..."

So if it's not possible with mod_wsgi (if that's inevitably "forking"), maybe I'm asking the wrong question. How can I set up Flask/Werkzeug on WebFaction to give developers the interactive debugger?

permanent link

answered 25 Oct '10, 04:40

RobC
1112
accept rate: 0%

You would create a 'custom application' which will assign you a port. You should than set it up exactly as you do locally. As long as you can specify the port it broadcasts on as the one in the custom app it can be managed like any other application. I am not familiar with Flask/Werkzeug, to be honest this is the first time anyone has asked about it to my knowledge, but this can be done with django and its development server. I assume there must be a way to do this with your framework.

permanent link

answered 25 Oct '10, 12:19

johns
5.3k312
accept rate: 23%

edited 25 Oct '10, 12:20

It possible actually to use the web debugger even when running through mod_wsgi on webfaction. You just wrap your application callable with Werkzeug DebuggedApplication rather than depend on app.debug = True config to do it for you. Other mod_wsgi restriction to make the debugger work still apply. Make sure to run in daemon mode, 1 process. More than 1 threads in daemon mode is fine.

from flask import Flask, render_template, request, redirect
from flaskext.sqlalchemy import SQLAlchemy

app = Flask(__name__)

from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(app, evalex=True)

Of course this assume you're mature enough to know when to do this on production machine. In my case, the site is not going live yet and I'm in quick fix mode to get it live.

permanent link

answered 07 Apr '12, 03:40

k4ml
1613
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×55
×44
×13
×2
×1

question asked: 24 Oct '10, 04:41

question was seen: 10,114 times

last updated: 07 Apr '12, 03:40

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM