Project

General

Profile

ModjyTroubleShooting » History » Version 2

Alan Kennedy, 2011-06-27 08:44 PM
Adding a section on the "'NoneType' has no attribute 'endswith'" error.

1 1 Alan Kennedy
h1. Trouble shooting modjy installations
2
3
By far the best way to get modjy running is to use the demo modjy application, distributed with jython, in the *Demo* directory, sub-directory *modjy_webapp*.
4
5
Don't forget to place the *jython.jar* file in the *WEB-INF/lib* directory!
6
7
If you're deploying a Django application, I highly recommend using the war packaging tool built, described on the [[ModjyAndDjango|Modjy and Django]] page: it configures everything correctly and prevents possible problems.
8
9
Similarly, the [[ModjyAndPylons|modjy and Pylons]] page describes the "snakefight":http://pypi.python.org/pypi/snakefight war-building tool, which does a similar job for Pylons.
10
11
h2(#noclassdef). java.lang.NoClassDefFoundError: com/xhaus/modjy/ModjyJServlet.
12
13
If you see this error, this means that your servlet container cannot find the java class *com.xhaus.modjy.ModjyJServlet*, which is the only java class used in modjy.
14
15
The likely cause of this issue is one of the following
16
17
 # The container cannot find the *jython.jar* file, which contains the class file.
18
 # The container cannot load the class from the *jython.jar* file, either for permissions or security reasons.
19
20
I recommend reading the documentation on [[ModjyDeployment#Placing-the-jythonjar-file|placing the jython.jar file]] 
21
22
h2(#importerror). ImportError: no module named modjy
23
24
There are two parts to modjy: a java part (actually a single java class) and a jython part. The majority of modjy is implemented in jython, with the entry point in a file called *modjy.py*. The java servlet component of modjy tries to import this module: if it fails, you will see the error above.
25
26
Obviously, you have to configure things such that modjy can find the *modjy.py* module and supporting modules. Which you can do by
27
28
 # Setting the *python.home* property. See the [[ModjyDeployment#Configuring-modjy|modjy deployment documentation]] for how to do this.
29
 # You can also copy the contents of the jython *Lib* directory into the *WEB-INF/lib-python* directory. This directory is automatically added to *sys.path* and any modules contained in it can be imported. To do this, copy every file and directory from the *Lib* directory of your jython installation into *WEB-INF/lib-python*, and that should solve your import problem.
30
 # It is also possible to package the entire jython *Lib* directory into a single file, which you then copy into *WEB-INF/lib-python*. This process is described on the [[ModjyGoogleAppEngine|running modjy on google appengine]] page, under the heading "Making the jython library accessible".
31
32 2 Alan Kennedy
h2(#endswithnone). Caught AttributeError while rendering: 'NoneType' object has no attribute 'endswith'
33
34
This error appears to occur when running "Django on Jython":http://code.google.com/p/django-jython/, as described in this bug report: "Problem with Websphere Application Server 6.1":http://code.google.com/p/django-jython/issues/detail?id=64 .
35
36
As described in that bug report, the underlying error is reported from the "gettext module":http://docs.python.org/library/gettext.html , which needs to find data files in the jython home directory in order to do its job.
37
38
The real cause of the problem is that gettext uses the value in *sys.prefix* to find the location of the jython home directory. If the value of *sys.prefix* is None, then its attempt to load data files will fail with the "'NoneType' object has no attribute 'endswith'" error.
39
40
To fix this problem, there must be a value of *sys.prefix*. For further information on what *sys.prefix* means and how its value is set, read "Finding the registry file":http://wiki.python.org/jython/UserGuide#finding-the-registry-file .
41
42
The quickest way to solve this problem is to set a value for the *python.home* property in the *web.xml* for your modjy application. Read [[ModjyConfiguration|Modjy Configuration]] for how to set the value of this property.
43
44 1 Alan Kennedy
h2(#other). Other problems.
45
46
If you experience other problems deploying WSGI applications with modjy, then please either file a bug on the "Jython bug tracker":http://bugs.jython.org or send an email to the "Jython Users":https://lists.sourceforge.net/lists/listinfo/jython-users mailing list.