Python CGI可执行脚本下载/显示脚本代码 [英] Python CGI executable script downloads / shows script code

查看:148
本文介绍了Python CGI可执行脚本下载/显示脚本代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很久以前写的脚本(getWords.py)以前在我的本地主机上可以执行( http://local.example.com/getWords.py?query-string )

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

我的python脚本开始是这样的:

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()

我已启用ExecCGI

I have enabled ExecCGI

cat/etc/apache2/sites-available/example

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>

但是脚本仍然可以强制下载(FireFox)或显示脚本代码(Chrome).

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

在我的主机(Webfaction)上,其运行于 http://example.com/getWords. py?query-string

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

推荐答案

您是否在apache2中添加了cgi处理程序

Did u add cgi handler in apache2

AddHandler cgi-script .py

AddHandler cgi-script .py

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

这篇关于Python CGI可执行脚本下载/显示脚本代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆