-1

I'm trying to setup python / apache / WSGI on windows.

I have the following installed, all 32-bit and vc9:

  • Apache 2.4
  • Python 2.7.9
  • Mod_WSGI.so in the modules folder.

http://localhost/ Displays the Apache Haus web page successfully -- Apache is running and serving.

Here is my "Hello World" python script:

def application(environ, start_response):
    status = '200 OK'
    output = 'This is my Website!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Here is my Apache config:

WSGIScriptAlias /wsgi "C:/wsgi_app/wsgi_app.py"
<Directory "C:/wsgi_app">
AllowOverride None
Options MultiViews
Require all granted
</Directory>

This version will display the file in plain-text, rather than interpreting it.

If I change options to none...

WSGIScriptAlias /wsgi "C:/wsgi_app/wsgi_app.py"
<Directory "C:/wsgi_app">
AllowOverride None
Options none
Require all granted
</Directory>

I get 404 Not Found on http://localhost/wsgi

The apache error log doesn't have much that seems too useful for troubleshooting.

[Wed Feb 10 16:17:49.293987 2016] [wsgi:warn] [pid 4448:tid 336] mod_wsgi: Compiled for Python/2.7.9+.
[Wed Feb 10 16:17:49.293987 2016] [wsgi:warn] [pid 4448:tid 336] mod_wsgi: Runtime using Python/2.7.9.
[Wed Feb 10 16:17:49.325187 2016] [mpm_winnt:notice] [pid 4448:tid 336] AH00354: Child: Starting 64 worker threads.
[Wed Feb 10 16:17:52.538793 2016] [wsgi:error] [pid 4448:tid 1040] [client ::1:54402] Target WSGI script not found or unable to stat: C:/wsgi_app/wsgi_app.py

"LoadModule access_compat_module modules/mod_access_compat.so" is uncommented, if that matters.

Any ideas on how to get this page to load / other apache config changes to try?

Do I need to change a python config somewhere?

  • Did you read the contents of the error log you published? E.g., "Target WSGI script not found or unable to stat: C:/wsgi_app/wsgi_app.py" – Andrey Sapegin Feb 18 '16 at 9:17
  • @some1, what is the content of C:/wsgi_app directory? Can you post an exact listing of the files in this directory? – Diamant Feb 19 '16 at 8:27
1
+50

From the error you are getting:

[wsgi:error] [pid 4448:tid 1040] [client ::1:54402] Target WSGI script not found or unable to stat: C:/wsgi_app/wsgi_app.py

It is highly likely that you have no file with the name "wsgi_app.py" in the "C:/wsgi_app/" directory.

Now what does the Options Multiviews do?

Here is a quote from Apache 2.4 documentation:

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

As you can see from the above explanation, when Multiviews option is enabled, and since a file named wsgi_app.py doesn't exist, the server will try to look for files named wsgi_app.py.*.

I suspect you have a file named wsgi_app.py.txt in the directory, and it's content get's displayed. You have probably created a text file in windows to create the wsgi_app.py file. In Windows when folder option "hide known file type extensions" is enabled, then it will hide the .txt extension of a file. As a result, a file named wsgi_app.py.txt will just be shown as wsgi_app.py.

When there is no Multiviews option anymore, the server is looking for a file exactly named "wsgi_app.py", and returning the error, being unable to find it.

  • Yep, sooo much hassle b/c windows hid the file extension and I completely forgot it does that. Thank you. – some1 Feb 24 '16 at 23:03

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.