Greetings. I use:

  • Windows 10 64-bits
  • Apache 2.4 VC14
  • Python 3.6

Download the compiled mod_wsgi ‑ 4.5.17 + ap24vc14 ‑ cp36 ‑ cp36m ‑ win_amd64.whl package from this source

Using the pip install command installed this package. Using the command

mod_wsgi-express module-config I received the following config for apache:

 LoadFile "c:/program files/python36/python36.dll" LoadModule wsgi_module "c:/program files/python36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd" WSGIPythonHome "c:/program files/python36" 

Added it to httpd.conf . I started the apache, opened localhost , I look at the response header. I see there: Server: Apache / 2.4.27 (Win64) mod_wsgi / 4.5.17 Python / 3.6

As I understand it, this means that mod_wsgi was successfully installed on Apache . I add to httpd.conf :

 WSGIScriptAlias /wsgi "D:/test/django.py" <Directory "D:/test"> <Files django.py> Require all granted </Files> </Directory> 

The contents of the django.py file are as follows:

 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] 

I restarted Apache, opened localhost / wsgi and got a 500 Internal Server Error error. I go to Apache's logs and there:

 [Tue Aug 08 11:06:08.389722 2017] [wsgi:error] [pid 1228:tid 1260] [client ::1:54302] mod_wsgi (pid=1228): Exception occurred processing WSGI script 'D:/test/django.py'. [Tue Aug 08 11:06:08.390722 2017] [wsgi:error] [pid 1228:tid 1260] [client ::1:54302] TypeError: sequence of byte string values expected, value of type str found\r 

Can anyone have any idea how to fix this error?

    1 answer 1

    Understood. It was necessary to return a non-simple string, that is, the contents of the django.py file should be as follows:

     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.encode('UTF-8')]