0

I'm working on running Django + httpd using mod_wsgi.

I've read up the docs and configured httpd.conf as required. I'm running Python2.7 on Centos5.5

I'm getting a strange "syntax" error which looks like a version conflict to me. Any pointers ?

Here are my Apache error logs:

[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85] mod_wsgi (pid=32765): Target WSGI script '/home/sbose/PATH/TO/wsgi.py' cannot be loaded as Python module.
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85] mod_wsgi (pid=32765): Exception occurred processing WSGI script '/home/sbose/PATH/TO/wsgi.py'.
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85] Traceback (most recent call last):
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85]   File "/home/sbose/PATH/TO/wsgi.py", line 10, in ?
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85]     import django.core.handlers.wsgi
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 84
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85]      self.buffer = b''
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85]                      ^
[Tue Aug 27 19:12:01 2013] [error] [client 10.104.22.85]  SyntaxError: invalid syntax

UPDATE: I just figured out that Apache was running Python2.4 Also, FYI,I had installed mod_wsgi with yum.

Thanks.

sbose
  • 1,791
  • 5
  • 24
  • 46
  • recheck the traceback, the problem may be is from there – drabo2005 Aug 27 '13 at 14:07
  • Thanks,I get that. That is not the code I wrote :-| – sbose Aug 27 '13 at 14:16
  • 1
    You might want to see why `Target WSGI script '/home/sbose/PATH/TO/wsgi.py' cannot be loaded as Python module` error is occuring. May be [this post](http://stackoverflow.com/questions/6454564/target-wsgi-script-cannot-be-loaded-as-python-module) ? – karthikr Aug 27 '13 at 14:17
  • Thanks, but this : "ImportError: No module named django.core.handlers.wsgi" is clearly not my case :) – sbose Aug 27 '13 at 14:22

1 Answers1

1

b strings were introduced between 2.4 and 2.7 (I don't know the exact release).

To check your Python version:

>>> import sys
>>> sys.version
'2.4.4 (#1, Jul 12 2013, 10:47:50) \n[GCC 4.7.3]'

Log it, if you want it to be in your apache log files.

Paco
  • 4,520
  • 3
  • 29
  • 53
  • https://github.com/django/django/blob/master/django/core/handlers/wsgi.py That's where self.buffer=b' ' is. – sbose Aug 27 '13 at 14:09
  • Do you even understand this code? Otherwise, b is not a variable defined in the scope, so it must be `self.buffer = ''` – Paco Aug 27 '13 at 14:11
  • 1
    This is what the b is supposed to be implying http://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal – sbose Aug 27 '13 at 14:13
  • What version of Python are you running? It doesn't work in Python 2.4 here, but works in Python 2.7 – Paco Aug 27 '13 at 14:19
  • 1
    I have both installed ( 2.4 was the default ). Any idea how I should be checking which one is being used by Apache? – sbose Aug 27 '13 at 14:24