apache python error - python

I am getting this in my error log file. Ive been searching for asolution but have found nothing. I am trying to deploy django with mod_wsgi.
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] ImportError: /usr/lib/python2.6/lib-dynload/_functools.so: wrong ELF class: ELFCLASS32
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] mod_wsgi (pid=20219): Target WSGI script '/home/dbs/public_html/test.wsgi' cannot be loaded as Python module.
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] mod_wsgi (pid=20219): Exception occurred processing WSGI script '/home/dbs/public_html/test.wsgi'.
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] Traceback (most recent call last):
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] File "/home/dbs/public_html/test.wsgi", line 6, in <module>
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] import django.core.handlers.wsgi
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] File "/home/dbs/sites/domain.com/django/core/handlers/wsgi.py", line 2, in <module>
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] from threading import Lock
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] File "/usr/lib/python2.6/threading.py", line 13, in <module>
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] from functools import wraps
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] File "/usr/lib/python2.6/functools.py", line 10, in <module>
[Wed Jun 13 12:15:53 2012] [error] [client 207.46.13.117] from _functools import partial, reduce

You have the wrong version of the functional module installed. Either install the correct binary version, or use the pure-python version.

Related

Python: Flask import failing

I'm trying to deploy a Flask app on Apache using mod_wsgi. Im using a virtual environment. But the below line is failing.
from flask import Flask
Error:
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] mod_wsgi (pid=6937): Target WSGI script '/var/www/sample_rest/sample_rest.wsgi' cannot be loaded as Python module.
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] mod_wsgi (pid=6937): Exception occurred processing WSGI script '/var/www/sample_rest/sample_rest.wsgi'.
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] Traceback (most recent call last):
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/sample_rest.wsgi", line 5, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from sample_rest import sample_rest as application
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/sample_rest.py", line 2, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from flask import Flask, request, jsonify, make_response
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/flask/__init__.py", line 16, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from werkzeug.exceptions import abort
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/__init__.py", line 15, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from .serving import run_simple
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/serving.py", line 51, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from .exceptions import InternalServerError
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/exceptions.py", line 68, in <module>
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] from .utils import escape
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] File "/var/www/sample_rest/lib/python3.6/site-packages/werkzeug/utils.py", line 189
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] "area",
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] ^
[Wed Sep 23 07:58:50 2020] [error] [client 10.192.73.242] SyntaxError: invalid syntax
As you can see the error is within the code of flask itself. I'm using Python-3.6.2 which is supported by flask. The source code of flask in which it's showing error is also correct. What could be the issue ?
Sorry for posting this rather then commenting:
Try to install Flask 1.1.1 which worked for me:
pip install Flask==1.1.1

ImportError: No module named types

I am getting below error when I start the httpd server and access the app url -
[Tue Feb 21 22:01:51 2017] [error] [client 10.209.33.139] mod_wsgi (pid=15425): Target WSGI script '/scratch/gdudwadk/python-projects/newblog/app/wsgi.py' cannot be loaded as Python module.
[Tue Feb 21 22:01:51 2017] [error] [client 10.209.33.139] mod_wsgi (pid=15425): Exception occurred processing WSGI script '/scratch/gdudwadk/python-projects/newblog/app/wsgi.py'.
[Tue Feb 21 22:01:51 2017] [error] Traceback (most recent call last):
[Tue Feb 21 22:01:51 2017] [error] File "/scratch/gdudwadk/python-projects/newblog/app/wsgi.py", line 7, in <module>
[Tue Feb 21 22:01:51 2017] [error] from app import app as application
[Tue Feb 21 22:01:51 2017] [error] File "/scratch/gdudwadk/python-projects/newblog/app/app.py", line 1, in <module>
[Tue Feb 21 22:01:51 2017] [error] from flask import Flask
[Tue Feb 21 22:01:51 2017] [error] File "/scratch/gdudwadk/python-projects/newblog/venv/lib/python2.6/site-packages/flask/__init__.py", line 17, in <module>
[Tue Feb 21 22:01:51 2017] [error] from werkzeug.exceptions import abort
[Tue Feb 21 22:01:51 2017] [error] File "/scratch/gdudwadk/python-projects/newblog/venv/lib/python2.6/site-packages/werkzeug/__init__.py", line 17, in <module>
[Tue Feb 21 22:01:51 2017] [error] from types import ModuleType
[Tue Feb 21 22:01:51 2017] [error] ImportError: No module named types
This started happening after my machine was replaced with new one. Previously app was working fine.
I found one reference to python2.7 in /etc/httpd/conf.d/wsgi.conf and that's what was causing the issue. After removing that, the app was up and running.. Thanks!

odoo mod_wsgi lxml.etree undefined symbol: PyUnicodeUCS2_DecodeLatin1

I try to configure mod_wsgi to access odoo thanks my domain name.
I followed this tutorial.
But when I go to my site I get this error :
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] mod_wsgi (pid=30445): Target WSGI script '/opt/odoo-v9-prod/openerp-wsgi.py' cannot be loaded as Python module.
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] mod_wsgi (pid=30445): Exception occurred processing WSGI script '/opt/odoo-v9-prod/openerp-wsgi.py'.
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] Traceback (most recent call last):
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp-wsgi.py", line 15, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import openerp
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/__init__.py", line 58, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import modules
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/modules/__init__.py", line 8, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] from . import db, graph, loading, migration, module, registry
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/modules/graph.py", line 13, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import openerp.osv as osv
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/osv/__init__.py", line 4, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] import osv
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/osv/osv.py", line 4, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] from ..exceptions import except_orm
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] File "/opt/odoo-v9-prod/openerp/exceptions.py", line 15, in <module>
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] from lxml import etree
[Thu Nov 03 16:00:57 2016] [error] [client 176.189.147.89] ImportError: /usr/local/lib/python2.7.9/lib/python2.7/site-packages/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1
I test my python encodage and it is UCS2.
I reinstalled lxml.
Your mod_wsgi is compiled for a different Python installation than the Python virtual environment you are trying to force it to use, or the Python shared library it is finding. Worse is that what ever it is using was compiled with different width for Unicode character support. You need to uninstall mod_wsgi and reinstall mod_wsgi from source code and compile it against the specific Python version you do want to use, forcing it to use the correct shared library if necessary. You may also want to consider reinstalling your custom Python version to use a configuration which aligns with what is generally regarded as best practice for the platform. Linux system usually use 4 byte Unicode, not 2.
Some stuff for you to read:
http://modwsgi.readthedocs.io/en/develop/user-guides/checking-your-installation.html#python-shared-library
http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html
Ignore the fact that the latter talks about Docker, all still relevant to normal Python install as well.

How can I import my own modules on webserver?

I am developing a website and want to put some files on the server. The problem is that I can only import python modules ( e.g. "import os"), but somewhy, can not import my own modules:
test1.py:
import test2
test2.py:
print ("Content-type:text/html\n\n")
print ("<html>")
print ("<head>")
print ("<title>Error</title>")
print ("</head>")
print ("<body>")
print (" hello world 2")
print ("</body>")
print ("</html>")
If I click www.mywebsite.com/test2.py, then I recieve "hello world" on the screen.
However, if I click www.mywebsite.com/test1.py, I get "500 internal server error." I found out that it is some problem with not being able to import my modules.
p.s. since I am on a shared server, I can not changes sys path etc....
Here is a trace I got in errors.log:
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] mod_python (pid=17816, interpreter='delekulator.co.il', phase='PythonHandler', handler='mod_python.cgihandler'): Application error
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] ServerName: 'delekulator.co.il'
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] DocumentRoot: '/var/www/vhosts/mywebsite.com/httpdocs'
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] URI: '/test1.py'
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Location: None
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Directory: '/var/www/vhosts/mywebsite.com/httpdocs/'
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Filename: '/var/www/vhosts/mywebsite.com/httpdocs/test1.py'
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] PathInfo: ''
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] Traceback (most recent call last):
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch\n default=default_handler, arg=req, silent=hlist.silent)
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target\n result = _execute_target(config, req, object, arg)
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target\n result = object(arg)
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] File "/usr/lib/python2.6/dist-packages/mod_python/cgihandler.py", line 96, in handler\n imp.load_module(module_name, fd, path, desc)
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] File "/var/www/vhosts/mywebsite.com/httpdocs/test1.py", line 1, in <module>\n import test2
[Thu Jun 11 00:18:09 2015] [error] [client 85.65.174.249] ImportError: No module named test2
In the last line, you can see that the server writes "ImportError: No module named test2"
How can I fix it?
From your description, your program did not found your own module, because you did not give your module's path. Now there are two methods to solve it:
Assume your module's path is: /srv/modules/xxxx.py
First you should import your module in your program: import xxxx
command line:Before you run your program with command line, give the path first. command:
export PYTHONPATH=/srv/modules.Then run your program.
add two lines of codes in your program:
import sys
sys.path.append("/srv/modules")
Use any one way above, you should run your program success.I hope this can help you.
Modules should be in the Python path or in the same directory where the executable is.
Then you do like usually
import test2
test2.some_function() # or whatever.

Why can't I execute another python script using the subprocess module via a webserver

Having a problem envoking another script, by the way it works fine from the console when I just call python main.py (which then calls test3.py) but when I do it via the webserver it gives the error below which is cryptic
I can't call this (test3 is just a print...)
#proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)
but this works fine
proc = subprocess.Popen(['ls', '-la'], stdout=subprocess.PIPE)
Error Log in /var/log/httpd-error.log on FreeBSD
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] Traceback (most recent call last):
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/www/apache22/data/main2.py", line 22, in <module>
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] proc = subprocess.Popen(['python', 'test3.py'], stdout=subprocess.PIPE)
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/lib/python2.7/subprocess.py", line 679, in __init__
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] errread, errwrite)
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File "/usr/local/lib/python2.7/subprocess.py", line 1228, in _execute_child
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] raise child_exception
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] OSError
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] :
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] [Errno 2] No such file or directory
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61]
[Thu Mar 01 12:26:55 2012] [error] [client 64.102.194.61] File does not exist: /usr/local/www/apache22/data/favicon.ico
The python executable is not in the webservers executable PATH. The webserver may also be secured with a chroot or similar techniques and therefore be unable to access the python installation.
Try specifying the full path of the python executable (you can find it out interactively with the which command), like this:
proc = subprocess.Popen(['/usr/bin/python', 'test3.py'], stdout=subprocess.PIPE)
Could you directly import your test3 code in to the project instead of calling it through the OS?
Are your relative paths all correct? It kind of sounds like you might be running something from the wrong directory or missing some needed files in the directory on the remote machine.

Categories