3

I have a Python CGI webapp that isn't working, and I don't know how to start narrowing down the problem. What can I do?


Note. I really appreciate the answer to this same question for Perl, and I wish I had one for Python. Some things similar, but most are different. That's my template for asking the question, so if you feel it should be asked differently, feel free to edit.

Community
  • 1
  • 1
Merchako
  • 789
  • 1
  • 8
  • 19
  • Have you checked out your server's error logs? – JPeroutek Jul 29 '15 at 15:24
  • That's exactly the kind of step that would be in the answer (among others). Also, I have no idea how to do that (BTW no admin privilege). – Merchako Jul 29 '15 at 15:25
  • @JPeroutek Frequently the server error logs are insufficient on their own to actually _understand_ what the problem at hand is. Given e.g. `[Mon Sep 25 12:17:48.291168 2017] [http:error] [pid 12] [client 172.20.0.1:53312] AH02429: Response header name ' – Thorbjørn Ravn Andersen Sep 25 '17 at 12:48

1 Answers1

4
  1. Check the server's error logs. For example on Apache the path may be /var/log/apache/error.log or /var/log/httpd/error_log.

  2. Make sure your script is executable (chmod +x script.py).

  3. Make sure your script has a she-bang line (#!/usr/bin/env python).

  4. Some configurations only allow CGI scripts to execute if they're in a /cgi-bin/ directory, you can confirm by looking at the server's configuration or just try moving your script into that directory.

  5. Try running your script from the command line (./script.py). It should print something and exit successfully (you may need to set a few CGI environment variables if your script depends on them).

  6. Replace your script with a minimal script that just prints "Content-Type: text/plain\n\nHello world". This should tell you if CGI is working at all on the server.

  7. Put import cgitb; cgitb.enable() at the top of your file (first line below the shebang line) to capture any errors and show you the traceback. You should turn this off once you've solved the problem, because it can be a security risk to expose this information.

If you don't have access to the logs then you will need to ask the server's administrator for help, file a support ticket, etc. It's also helpful if you post what web server you're running under, what the web server configs look like, which python version, what your CGI script looks like, etc.

Merchako
  • 789
  • 1
  • 8
  • 19
Steven Kryskalla
  • 14,179
  • 2
  • 40
  • 42