Note that there are some explanatory texts on larger screens.

plurals
  1. PORun python cgi script in browser w/o errors
    primarykey
    data
    text
    <p>I'm trying to run it on <strong>localhost</strong>. A short introduction. Some links I've read before post: <a href="https://stackoverflow.com/questions/7929848/how-to-run-python-cgi-script">How to run Python CGI script</a> <a href="https://stackoverflow.com/questions/6611608/how-can-i-run-python-cgi-scripts-on-my-web-server">How can I run Python CGI scripts on my web server?</a> most precise: <a href="https://stackoverflow.com/questions/8044232/need-help-to-configure-apache-server-to-run-cgi-script-written-in-python">Need Help to Configure apache Server to run CGI Script written in Python</a> And also official <a href="http://httpd.apache.org/docs/1.3/misc/FAQ.html#CGIoutsideScriptAlias" rel="nofollow noreferrer">http://httpd.apache.org/docs/1.3/misc/FAQ.html#CGIoutsideScriptAlias</a> <a href="http://www.editrocket.com/articles/python_apache_windows.html" rel="nofollow noreferrer">http://www.editrocket.com/articles/python_apache_windows.html</a> and other...</p> <hr> <p>All steps they suggest to configure Apache for .cgi and .py scripts: 1) </p> <blockquote> <p>install libapache2-mod-wsgi</p> </blockquote> <p>[done] 2) check the script is executable and available for apache ~$ ls -lah /var/www/cgi-bin/cgi101.py </p> <pre><code>-rwxrwxr-x 1 user user 318 2012-11-27 03:03 /var/www/cgi-bin/cgi101.py </code></pre> <p>3) edit /etc/apache2/sites-available/default[<strong>updated to actual</strong>]:</p> <pre><code>&lt;VirtualHost *:80&gt; ServerAdmin webmaster@localhost DocumentRoot /var/www &lt;Directory /&gt; Options FollowSymLinks AllowOverride None &lt;/Directory&gt; # &lt;Directory /var/www&gt; &lt;Directory /var/www/cgi-bin&gt; Options Indexes FollowSymLinks MultiViews ExecCGI AllowOverride None Order allow,deny allow from all AddHandler cgi-script .cgi .py # AddHandler wsgi-script .wsgi &lt;/Directory&gt; ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ &lt;Directory "/usr/lib/cgi-bin"&gt; AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all &lt;/Directory&gt; ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" &lt;Directory "/usr/share/doc/"&gt; Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 &lt;/Directory&gt; &lt;/VirtualHost&gt; </code></pre> <p>or with</p> <pre><code>&lt;Directory /var/www/cgi-bin&gt; </code></pre> <p>then restart Apache</p> <pre><code>sudo /etc/init.d/apache2 restart </code></pre> <p>and finally, try the script. Something like[<strong>updated to actual</strong>]:</p> <pre><code>#!/usr/bin/python3 import cgi form = cgi.FieldStorage() # parse form data print('Content-type: text/html\n') # hdr plus blank line print('&lt;title&gt;Reply Page&lt;/title&gt;') # html reply page if not 'user' in form: print('&lt;h1&gt;Who are you?&lt;/h1&gt;') else: print('&lt;h1&gt;Hello &lt;i&gt;%s&lt;/i&gt;!&lt;/h1&gt;' % cgi.escape(form['user'].value)) </code></pre> <p>On the output i get </p> <blockquote> <p><strong>404 Not found</strong></p> </blockquote> <p>error. WTH? I've tried both and /var/www. And my python path to python3:</p> <pre><code>~$ ls -lah /usr/bin/python* ... lrwxrwxrwx 1 root root 9 2011-10-05 23:53 /usr/bin/python3 -&gt; python3.2 lrwxrwxrwx 1 root root 11 2012-10-20 06:17 /usr/bin/python3.2 -&gt; python3.2mu -rwxr-xr-x 1 root root 2.8M 2012-10-20 06:17 /usr/bin/python3.2mu ... </code></pre> <p>that's why i use</p> <pre><code>#!/usr/bin/python3 </code></pre> <p>Thanks in advance!</p> <hr> <p>[<strong>updated</strong>] /var/log/apache2/error.log</p> <pre><code>[Tue Nov 27 13:47:56 2012] [error] [client 127.0.0.1] script not found or unable to stat: /usr/lib/cgi-bin/script.py, referer: http://localhost/cgi1$ </code></pre> <p>Why it looks for script.py in /usr/lib/ ??</p> <hr> <p>[<strong>updated</strong>] I closed my eyes while reading the lines</p> <pre><code> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ &lt;Directory "/usr/lib/cgi-bin"&gt; </code></pre> <p>It must be path to executable .cgi or .py in /var/www/cgi-bin. Thanks Evert and everyone!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload