jvandal / modwsgi

Automatically exported from code.google.com/p/modwsgi
0 stars 0 forks source link

3.0c6/Python 3.1.1 import failed #168

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.

Set up a virtual host:

<VirtualHost *:80>
    ServerName www.hello.com:80
    DocumentRoot "D:/path/to/hello/public"
    Alias /favicon.ico "D:/path/to/hello/public/favicon.ico"
    WSGIScriptAlias / "D:/path/to/hello/hello.wsgi"
</VirtualHost>

2.

Create a file "D:/path/to/hello/test.py" with the following codes:

def f():
    pass

3.

Edit "D:/path/to/hello/hello.wsgi":

import test

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

4.

Restart apache, and visit http://www.hello.com/

5.

Internal error with the following messages:

[Mon Nov 16 19:23:10 2009] [error] [client 127.0.0.1] mod_wsgi (pid=364):
Target WSGI script 'D:/path/to/hello/hello.wsgi' cannot be loaded as Python
module.
[Mon Nov 16 19:23:10 2009] [error] [client 127.0.0.1] mod_wsgi (pid=364):
Exception occurred processing WSGI script 'D:/path/to/hello/hello.wsgi'.
[Mon Nov 16 19:23:10 2009] [error] [client 127.0.0.1] Traceback (most
recent call last):\r
[Mon Nov 16 19:23:10 2009] [error] [client 127.0.0.1]   File
"D:/path/to/hello/hello.wsgi", line 1, in <module>\r
[Mon Nov 16 19:23:10 2009] [error] [client 127.0.0.1]     import test\r
[Mon Nov 16 19:23:10 2009] [error] [client 127.0.0.1] ImportError: No
module named test\r

What is the expected output? What do you see instead?

  "Hello World!", but see internal error.

What version of the product are you using? On what operating system?

  WindowsXP SP2/i386
  Apache 2.2.13 winnt MPM
  Python 3.1.1/i386
  modwsgi 3.0c6

Please provide any additional information below.

  Python info:

C:\WINDOWS\system32>python
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', 'C:\\WINDOWS\\system32\\python31.zip', 'C:\\Python31\\DLLs',
'C:\\Python31\
\lib', 'C:\\Python31\\lib\\plat-win', 'C:\\Python31',
'C:\\Python31\\lib\\site-p
ackages']

Original issue reported on code.google.com by dio...@gmail.com on 16 Nov 2009 at 11:24

GoogleCodeExporter commented 8 years ago
What you are seeing is exactly what expect to see. This is because the 
directory that WSGI script files are loaded 
from are not part of Python module search path. Some of the reasons why this 
isn't the case is mentioned in:

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Embedded_
Mode

but there are a lot of other reasons besides including security issues related 
to putting application source code in 
Apache document directories and the general disaster that comes from trying to 
automatically add all script 
directories into sys.path.

In short, put all your .py files in a different directory outside of the 
document directory where the WSGI script file 
is. Then use one of the available methods for adding that separate directory to 
the Python module search path.

If want to discuss further, use the mod_wsgi mailing list.

Original comment by Graham.Dumpleton@gmail.com on 16 Nov 2009 at 11:40