I am trying getting starting with python web programming but I have a problem. I want to work with CGI
I installed Ampps web-server on pc (Linux). According to this instruction Apache Tutorial: Dynamic Content with CGI. I put my file index.pl in the folder '/usr/local/ampps/www/cgi-bin' and tried to accesses it
http://localhost/cgi-bin/index.py
Here is code of my file:
#!/usr/local/ampps/python/bin/python
print "Content-type: text/html\n\n"
print "Hello World from PythonStandard Hello World from a Python"
But it gives me mistake Sorry, the page you are looking for is currently unavailable.
Here is error log of Apache:
[Tue Jul 22 20:05:45.019799 2014] [cgi:error] [pid 11952] [client 127.0.0.1:38359] AH01215: (13)Permission denied: exec of '/usr/local/ampps/www/cgi-bin/index.py' failed
[Tue Jul 22 20:05:45.020262 2014] [cgi:error] [pid 11952] [client 127.0.0.1:38359] End of script output before headers: index.py
I corrected conf of Apache
AddHandler cgi-script .cgi .pl .py
it looked ok too
LoadModule cgi_module modules/mod_cgi.so
ScriptAlias /cgi-bin/ "{$path}/www/cgi-bin/"
What can be wrong else?
Your script needs to have the executable bit set (using chmod) and the Apache user or group (usually named 'Apache' or 'www-data' depending on your distro - you can check /etc/passwd to find out) must have the 'execute' permission on it.
I was getting similar errors. It seemed that the AMPPS installation of Python was missing one of the DLLs. I downloaded the 2.7 .msi package from ActiveState and installed it.
A couple of things before you start: the location, and the permissions.
I may be wrong on this, but Apache will be looking for the Python executable in the directory that was created for it in the AMPPS installation -- c:\whatever\whatever\ampps\python. I tried installing it in c:\whatever\whatever\ampps\python2.7, but it didn't work. I suppose I could have edited the httpd.conf file, but since the original installation wasn't working anyway, I overwrote the c:\w\w\ampps\python files.
I also ran the .msi as an administrator. This was tricky, because my company-issued machine doesn't let me simply right-click on an .msi and select "run as administrator." I finally went into the task manager (option 8 here: http://www.eightforums.com/tutorials/9564-run-administrator-windows-8-a.html), and put the full path to the downloaded file in the entry. And voila, "hello world."
Related
This is a duplicate question of this, however none of the answers there worked for me. I have done a lot of research into this and am completely stumped.
I am running a super simple python script called /var/www/cgi/test.py:
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import cgitb
print('Content-Type: text/html; charset=utf-8\n')
print("Hello world")
However when I attempt to access this through my server at: https://server.com/cgi/test.py I get the following message:
This obviously doesn't tell me much, so I checked the /var/log/apache2/error.log file and found the following:
[Tue Jan 25 11:55:10.622681 2022] [cgi:error] [pid 29052] [client REDACTED] AH01215: (8)Exec format error: exec of '/var/www/cgi/test.py' failed: /var/www/cgi/test.py
[Tue Jan 25 11:55:10.623144 2022] [cgi:error] [pid 29052] [client REDACTED] End of script output before headers: test.py
Following my research online, I have tried and done the following:
I have added the necessary configuration lines into the apache config file at /etc/apache2/apache2.conf. It looks like the following (I initially just had the ScriptAlias as I'm fairly certain that's all that's needed but it wasn't working so I added the <Directory> config too:
# work with the default configuration.
ScriptAlias /cgi/ /var/www/cgi/
<Directory "/var/www/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi .py
</Directory>
# Global configuration
#
"/etc/apache2/apache2.conf" 235L, 7355C
Restarted apache using sudo service apache2 restart since changing the config file
Changed the permissions of test.py to be chmod 777 test.py (overkill I know, but just in case)
Ensured the shebang is correct with which python3 returning /usr/bin/python3
I symlinked my crunchworld.conf as described in this post
Perhaps even more I'm forgetting. I'm truly at a loss, I feel like I've exhausted every avenue.
Does anyone have any idea why this error is still occurring?
Change the first line to
#!/usr/bin/env python3
from
#!/usr/bin/python3
Maybe this works?
I have a very simple python file including some HTML Code. It is supposed to just print out "Hallo" when run in the command line, and when opened in the Browser there should be a formatted HTML. Instead either way all it does is print the raw html-code.
Also IntelliJ says "unresolved reference 'print' ".
Any ideas, what is going wrong here?
I've added CGI configurations to https.conf, too.
Okay, there were some misconfigurations with the CGI. It was not interpreting the files in my MacBook "Sites" Folder, which I configured as my resource. Thus I had to change this in the https.conf:
here, both LoadModules needed to be active (#removed)
<IfModule !mpm_prefork_module>
LoadModule cgid_module libexec/apache2/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
LoadModule cgi_module libexec/apache2/mod_cgi.so
</IfModule>
then there came an internal server error, when opening the .py in the browser. the logfile said:
[Tue Dec 01 22:34:47.904341 2020] [cgi:error] [pid 1800] [client
::1:51615] End of script output before headers: test.py, referer:
http://localhost/~zehra/
I configured the CGI through changing http.conf , so it interpreted everything from my Sites folder as cgi.That worked.
Still, it doesn't work in the command line nor IntelliJ.
I installed trac using BitNami the other day and after restarting my computer I'm not able to get it running as a service today. I see in the error log this error
[Fri Dec 02 08:52:40.565865 2016] [:error] [pid 4052:tid 968] C:\Bitnami\trac-1.0.13-0\python\lib\site-packages\setuptools-7.0-py2.7.egg\pkg_resources.py:1045: UserWarning: C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\Python-Eggs is writable by group/others and vulnerable to attack when used with get_resource_filename. Consider a more secure location (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
Everyone's suggestion is to move the folder path PYTHON_EGG_CACHE to the C:\egg folder or to suppress the warning at the command line.
I've already set the PYTHON_EGG_CACHE for the system, I set it in trac's setenv.bat file, and in the trac.wsgi file but it's not picking up on the changes when I try to start the service.
Alternately I can't change the permissions on the folder in Roaming using chmod like in Linux, and I can't remove any more permissions on the folder in Roaming (myself, Administrators, System) as Corporate IT doesn't allow for Administrators to be removed and this isn't an unreasonable policy.
I found out that there was another service running on the 8080 port that I had setup trac on and that was causing the trouble. The error in the logs was not pointing to that as being the issue however.
My django application that used to make some shell commands by using python subprocess.Popen does not work anymore since I upgrade to ubuntu to 11.10
To simplify the problem, I put the faulty code into the wsgi script :
import os
import sys
from subprocess import Popen,PIPE
p=Popen(['/usr/bin/id'],stdout=PIPE,stderr=PIPE)
comm=p.communicate()
print comm,p.returncode
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
If I run this code directly by python, it works :
$ python -V
Python 2.7.2+
$ python django_wsgi.py
('uid=1002(www) gid=1002(www) groups=1002(www)\n', '') 0
If I run this code by apache (I just put the relevant URL into a browser), in the apache log, I got :
[Tue Nov 29 11:34:38 2011] [error] ('', '') -6
What is this error '-6' ???
The problem is that with my development server (Ubuntu 10.04, almost the same apache/wsgi version, same apache configuration file, same environment variables, but with python 2.6.5) it works well :
[Tue Nov 29 11:29:10 2011] [error] ('uid=1000(www) gid=1000(www) groups=1000(www)\\n', '') 0
Do you know why Popen is not work through apache anymore with python 2.7 ?
Because latest Python 2.7 has a bug in it which causes fork run in sub interpreters to fail.
http://bugs.python.org/issue13156
Presuming only hosting the one WSGI application, force use of the main interpreter rather than a sub interpreter by adding to your Apache configuration:
WSGIApplicationGroup %{GLOBAL}
My goal is to have Apache process a python script and output to the requesting client.
My server has both Python2.4 and Python2.5.5 installed. I have Apache configured to correctly process python scripts and tested with a simple test script. However, the real script I am trying to run requires Python2.5.5. Mod_Python seems to be utilizing Python2.4.
I am getting the following PythonDebug output when I request the file:
Mod_python error: "PythonHandler output.py"
...
AssertionError: Please use Python 2.5 or greater
Additional information:
Checking the Python version from the command line:
python -V returns Python 2.5.5
The Apache error log shows the following error type:
[Mon Mar 01 14:04:27 2010] [error] [client xxx.xxx.xxx.xxx] PythonHandler output: File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 464, in import_module\n module = imp.load_module(mname, f, p, d)
Python2.5.5 seems to be installed to a different directory than Python 2.4:
Python2.5.5 /usr/local/lib/python2.5
Python2.4 /usr/lib/python2.4/
Is there any way to update mod_python to use Python2.5.5?
No. Rebuild it against 2.5.5 instead.