Search code examples
mod-wsgiweb.pyapache2.4

Apache 2.4(32bit) Target WSGI script annot be loaded as Python module. web.py


os:widows 2012r2

web server: apache 2.4.23 (32bit)

python: 2.7.12

web framework: web.py 0.38

mod_wsgi: mod_wsgi-4.4.23+ap24vc9-cp27-cp27m-win32

I give the apache server system permissions, So reasons of permission can be excluded.

This whole process is:Http-> Apache 2.4->mod_wsgi->web.py

wsgi.conf:

WSGIScriptAlias / "C:/Apache24/htdocs/test.py/"

Alias /static "C:/Apache24/htdocs/static/"
AddType text/html .py

<Directory "C:/Apache24/htdocs/">
    Require all denied
    Require all granted
</Directory>

=================================================

the test.py:

coding:utf-8
import web
urls = (
    '/.*', 'hello',
    )

class hello:
    def GET(self):
        return "Hello, world."

app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()

=================================================

Then, It works! I open IE and type url: localhost:80, The page display: Hello, world.

Based on the above, I change the code of the wsgi.conf:

=================================================

WSGIScriptAlias / "C:/Apache24/htdocs/code.py/"

Alias /static "C:/Apache24/htdocs/static/"
AddType text/html .py

<Directory "C:/Apache24/htdocs/">
    Require all denied
    Require all granted
</Directory>

=================================================

And the code.py:

coding: utf-8

import web
from config.url import urls

app = web.application(urls, globals())

application = app.wsgifunc()

=================================================

Then apache still works,

but the error.log show:"Target WSGI script 'C:/Apache24/htdocs/code.py' cannot be loaded as Python module."

And the URL: localhost:80 can not work, display: "500 Internal Server Error"

Anybody can tell how to solve the problem? Thanks very much.

The error.log:

[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] mod_wsgi (pid=3780): Target WSGI script 'C:/Apache24/htdocs/code.py' cannot be loaded as Python module.
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] mod_wsgi (pid=3780): Exception occurred processing WSGI script 'C:/Apache24/htdocs/code.py'.
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] Traceback (most recent call last):
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159]   File "C:/Apache24/htdocs/code.py", line 5, in <module>
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159]     from config.url import urls
[Thu Aug 25 02:05:43.687446 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61159] ImportError: No module named config.url
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] mod_wsgi (pid=3780): Target WSGI script 'C:/Apache24/htdocs/code.py' cannot be loaded as Python module., referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] mod_wsgi (pid=3780): Exception occurred processing WSGI script 'C:/Apache24/htdocs/code.py'., referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] Traceback (most recent call last):, referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160]   File "C:/Apache24/htdocs/code.py", line 5, in <module>, referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160]     from config.url import urls, referer: 192.168.1.146
[Thu Aug 25 02:05:43.859495 2016] [wsgi:error] [pid 3780:tid 1248] [client 192.168.1.107:61160] ImportError: No module named config.url, referer: 192.168.1.146

Solution

  • The directory containing your config package/module is not in the Python module search path. You need to use theWSGIPythonPath directive to tell the Python interpreter run by mod_wsgi where it is.