Python CGI executable script downloads / shows script code

2024/10/15 11:25: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.pyprint "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.comDocumentRoot /home/username/Dropbox/vhosts/example/<Directory /home/username/Dropbox/vhosts/example>Options +Indexes +FollowSymLinks +MultiViews +ExecCGIAllowOverride AllOrder allow,denyallow from all</Directory>ErrorLog /var/log/apache2/error.example.logLogLevel warnCustomLog /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

Answer

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://en.xdnf.cn/q/117838.html

Related Q&A

My function returns None

I am new to Python and I was trying to solve this exercise, but keep getting None output. The question asked for a program in which the input is hours and rate and the output is the gross pay, includin…

Django undefined symbol: PyUnicode_AsUTF8

I am new to Python/Django. I have set up the environment needed to run Django project.When Im trying to migrate an existing project , it shows up this errordjango.core.exceptions.ImproperlyConfigured: …

using a variable keyword for an optional argument name with python argparse

I am using argparse for a python script I am writing. The purpose of the script is to process a large ascii file storing tabular data. The script just provides a convenient front-end for a class I have…

Error while setting up MongoDB with django using django mongodb engine on windows

Steps I followed :pip install git+htp://github.com/django-nonrel/[email protected]It did not work, so I downloaded the zip from the site "htp://github.com/django-nonrel/django" and pasted the…

Python login page with pop up windows

I want to access webpages and print the source codes with python, most of them require login at first place. I have similar problem before and I have solved it with the following code, because they are…

Calculate Scipy LOGNORM.CDF() and get the same answer as MS Excel LOGNORM.DIST

I am reproducing a chart in a paper using the LOGNORM.DIST in Microsoft Excel 2013 and would like to get the same chart in Python. I am getting the correct answer in excel, but not in python.In excel …

Python MySQLdb cursor.execute() insert with varying number of values

Similar questions have been asked, but all of them - for example This One deals only with specified number of values.for example, I tried to do this the following way:def insert_values(table, columns, …

Searching in a .txt file and Comparing the two values of a string in python?

"cadence_regulatable_result": "completeRecognition","appserver_results": {"status": "success","final_response": 0,"payload": {"…

How to perform an HTTP/XML authentication with requests

I am trying to authenticate to Docushare with Python 3.4 using requests 2.7. I am relatively new to Python and to the requests module but Ive done a lot of reading and am not able to make any more prog…

webPy Sessions - Concurrent users use same session and session timeout

I have a webPy app using sessions for user authentication. Sessions are initiated like so:web.config.debug=Falsestore = web.session.DiskStore(/path_to_app/sessions) if web.config.get(_session) is None:…