0

How can I turn on the cgitb debug on browser in wsgi?

# enable debugging
import cgitb
cgitb.enable()

def application(environ, start_response):

# build the response body possibly using the environ dictionary
response_body = 'The request method was %s' % environ['REQUEST_METHOD']

status = '200 OK'

response_headerx = [('Content-Type', 'text/plain'),
                   ('Content-Length', str(len(response_body)))]

# Send them to the server using the supplied function
start_response(status, response_headers)

return [response_body]

error only can be found in Apache log's error.log,

NameError: global name 'response_headers' is not defined, referer: http://127.0.0.1/python-

while on the browser, I get this,

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.

Error 500

127.0.0.1 Apache/2.4.7 (Win32) mod_wsgi/4.4.12 Python/2.7.10 PHP/5.6.4

Any ideas?

Run
  • 54,938
  • 169
  • 450
  • 748
  • The cgitb module is for use with CGI scripts, not WSGI applications. Instead see https://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Error_Catching_Middleware but don't use such things on production servers. – Graham Dumpleton Aug 14 '15 at 06:25
  • Thanks. But I get this error - `ImportError: No module named paste.exceptions.errormiddleware, ` – Run Aug 14 '15 at 06:49
  • `pip install paste` is what it takes – Run Aug 14 '15 at 07:00
  • I see typo in code. You created variable 'response_headerx', rename it to response_headers – Javed Sayyed Mar 27 '21 at 15:20

0 Answers0