Switching mod_python from using python2.4 to python2.5 - python

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.

Related

Apache "AH01215: (8)Exec format error" when attempting to run python script

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?

mod_wsgi - mod_wsgi-express error AH00526: Syntax error on line 16

This question is related with my question.
Actually I use the Apacha Version over Ubuntu 14.04 LTS 64bits:
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jul 22 2014 14:36:38
When I type command mod_wsgi-express start-server to check if it runs. It seems not running and I have an error:
root#website:/home/website# mod_wsgi-express start-server
Server URL : http://localhost:8000/
Server Root : /tmp/mod_wsgi-localhost:8000:0
Server Conf : /tmp/mod_wsgi-localhost:8000:0/httpd.conf
Error Log File : /tmp/mod_wsgi-localhost:8000:0/error_log
AH00526: Syntax error on line 16 of /tmp/mod_wsgi-localhost:8000:0/httpd.conf:
Error:\tApache has not been designed to serve pages while\n\trunning as root. There are known race conditions that\n\twill allow any local user to read any file on the system.\n\tIf you still desire to serve pages as root then\n\tadd -DBIG_SECURITY_HOLE to the CFLAGS env variable\n\tand then rebuild the server.\n\tIt is strongly suggested that you instead modify the User\n\tdirective in your httpd.conf file to list a non-root\n\tuser.\n
I have the same problem during installation to doom. Any suggest is welcome!
More Information:
Modules used in Apache:
Compiled in modules:
core.c
mod_so.c
mod_watchdog.c
http_core.c
mod_log_config.c
mod_logio.c
mod_version.c
mod_unixd.c
Python Version:
>>> print (sys.version)
2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2]
I had a similar issue trying to spin up a TurboGears python application. I was finally able to get it started by executing the start-server command with the user option included. I set the user option equal to the user running apache. In my case the user is "apache". See below.
[root#localhost ~]# mod_wsgi-express start-server --user=apache <path_to_my_wsgi_file>

Python web script doesn't run on apache

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."

Python CGI script - 500 error

I have python CGI script that runs perfect on my local Apache 2.2.22 server. It outputs correct result and so on. But when I try to execute it on virtual hosting, there is error 500.
I really have no idea why it does not works.
Apache error log looks like:
[Wed Jul 12 16:06:54 2013] [error] [client 89.223.235.12] Premature end of script headers: /home/u67442/rrrrr.com/cgi-bin/test.py
[Wed Jul 12 16:09:31 2013] [error] [client 89.223.235.12] Premature end of script headers: /home/u67442/rrrrr.com/cgi-bin/test.py
I've already tried following things:
I'm sure that path to interpreter is correct - #!/usr/local/bin/python. Another CGI script works fine with this path.
I have set chmod 755 to this script.
I have set end-of-line characters in UNIX-format.
I use correct HTTP-header: print "Content-type:text/html\n\n"
Output section of script:
print "Content-type:text/html\n\n"
print "<html>"
print "<head>"
print "<title>Results</title>"
print "<head><h2 align=center>Results</h2></head>"
print "</head>"
print '<body bgcolor="#e8f3d8">'
print "<hr>"
print "<b>Result = %s </b>" % str(round(total_sum, 5))
print "</body>"
print "</html>"
Funny that another VERY similar script with the same path, header, EOL, output and so on works perfect on local server and virtual hosting. And it's very strange that this script works fine on my local apache, but on virtual web hosting it crashes with 500 internal server error. I really don't know what to do. In technical support says that there is problem in my script.
There is only one idea - timeout of waiting of output. Data processing in my script takes about 15-25 seconds.
What can you advice?
Check your error_log.
If you can, run the script from the command line of the virtual host.
If you can, su - webserveruser and do it again.
Are you trying to import a module that is not present on the server?
Does the webserver process have permission to fetch the data that ends up in total_sum?
To narrow down the problem, try hard-coding a value for total_sum and commenting out the code that fetches data and computes it. Does the rest work then?
Does the virtual host run the same version of python as your local server? If not, check that your code works in both versions.
Problem solved. Problem was in the script. I replace function for data extraction from *.dat files from one of 'while' loops.
Anyway, I still do not understand why it worked on local server and didn't worked on virtual hosting.

Popen does not work anymore with apache/wsgi and python 2.7.2?

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}

Categories