Python CGI executable script downloads / shows script code

血红的双手。 提交于 2019-12-08 09:23:53

问题


A script I wrote long ago (getWords.py) used to be executable at my localhost (http://local.example.com/getWords.py?query-string)

My python script starts like this :

#!/usr/bin/env python
# chmod 755 getWords.py

print "Content-type: text/html\n\n"

import os, sys, time, cgi, cgitb, re
import json, hashlib, gzip, urllib, urllib2
cgitb.enable()

I have enabled ExecCGI

cat /etc/apache2/sites-available/example

<VirtualHost *:80>
    ServerName local.example.com
    DocumentRoot /home/username/Dropbox/vhosts/example/
    <Directory /home/username/Dropbox/vhosts/example>
        Options +Indexes +FollowSymLinks +MultiViews +ExecCGI
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.example.log
    LogLevel warn
    CustomLog /var/log/apache2/access.example.log combined
</VirtualHost>

But still the script force downloads (FireFox) or shows the script code (Chrome).

-rwxr-xr-x 1 username username 4794 Jul 14 17:15 getWords.py

Any idea what is wrong on my localhost ?

$ apache2 -v
Server version: Apache/2.4.12 (Ubuntu)
Server built:   Feb  4 2015 14:21:10
$ python -V
Python 2.7.3

On my host (Webfaction), its running at http://example.com/getWords.py?query-string


回答1:


Did u add cgi handler in apache2

AddHandler cgi-script .py

https://www.linux.com/community/blogs/129-servers/757148-configuring-apache2-to-run-python-scripts



来源:https://stackoverflow.com/questions/31446102/python-cgi-executable-script-downloads-shows-script-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!