Re: [jToolkit-users] Problems with hello world
Brought to you by:
davidfraser,
friedelwolff
From: Greenbeard <gre...@ya...> - 2003-10-15 04:01:12
|
OK, I replaced the __init__.py and now when Apache Restarts I get: --------------------------- Mod_python error: "PythonHandler jToolkit.web" Traceback (most recent call last): File "C:\Python22\Lib\mod_python\apache.py", line 335, in HandlerDispatch result = object(req) File "C:\Python22\Lib\site-packages\jToolkit\web\__init__.py", line 93, in handler server = getserver(modulename, instancename) File "C:\Python22\Lib\site-packages\jToolkit\web\__init__.py", line 67, in getserver module = __import__(modulename, globals(), locals(), [instancename]) File "C:/Program Files/Apache Group/Apache2/htdocs/\jtoolkit\demo\helloworld.py", line 24, in ? class HelloWorldServer(server.AppServer): File "C:/Program Files/Apache Group/Apache2/htdocs/\jtoolkit\demo\helloworld.py", line 26, in HelloWorldServer serverclass = HelloWorldServer NameError: name 'HelloWorldServer' is not defined ======================== However, If I refresh the page I get Mod_python error: "PythonHandler jToolkit.web" Traceback (most recent call last): File "C:\Python22\Lib\mod_python\apache.py", line 335, in HandlerDispatch result = object(req) File "C:\Python22\Lib\site-packages\jToolkit\web\__init__.py", line 93, in handler server = getserver(modulename, instancename) File "C:\Python22\Lib\site-packages\jToolkit\web\__init__.py", line 78, in getserver raise AttributeError(errormessage) AttributeError: module 'demo.helloworld' has no attribute 'HelloWorldConfig' module is <module 'demo.helloworld' from 'C:/Program Files/Apache Group/Apache2/htdocs/jtoolkit/\demo\helloworld.pyc'>, attributes are ['__builtins__', '__doc__', '__file__', '__name__', 'server', 'widgets'] Python path is ['C:/Program Files/Apache Group/Apache2/htdocs/jtoolkit/\\', 'C:/Program Files/Apache Group/Apache2/htdocs/\\', 'C:\\Python22\\Lib\\site-packages\\Pythonwin', 'C:\\Python22\\Lib\\site-packages\\win32', 'C:\\Python22\\Lib\\site-packages\\win32\\lib', 'C:\\Python22\\Lib\\site-packages', 'C:\\Python22\\Lib', 'C:\\Python22\\DLLs', 'C:\\Python22\\Lib\\lib-tk', 'C:\\Program Files\\Apache Group\\Apache2', 'C:\\Program Files\\Apache Group\\Apache2\\bin', 'C:\\Python22'] ======= Ok, well I had to tweak the httpd.conf to get this far look like <Directory "C:\\Program Files\\Apache Group\\Apache2\\htdocs\\jtoolkit"> SetHandler python-program PythonHandler jToolkit.web #PythonOption jToolkit.module jtoolkit.demo.helloworld PythonOption jToolkit.module demo.helloworld PythonOption jToolkit.instance HelloWorldConfig PythonDebug On </Directory> So, I went interactive on this and here is what I got: >>> from demo import helloworld Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\PYTHON22\LIB\SITE-PACKAGES\JTOOLKIT\demo\helloworld.py", line 24, in ? class HelloWorldServer(server.AppServer): File "C:\PYTHON22\LIB\SITE-PACKAGES\JTOOLKIT\demo\helloworld.py", line 26, in HelloWorldServer serverclass = HelloWorldServer NameError: name 'HelloWorldServer' is not defined >>> import demo >>> dir(demo) ['__all__', '__builtins__', '__doc__', '__file__', '__name__', '__path__', 'helloworld'] >>> from demo import helloworld >>> dir(helloworld) ['__builtins__', '__doc__', '__file__', '__name__', 'server', 'widgets'] >>> So I think I must have something configured incorrectly in either my httpd.conf or PYTHONPATH. Could it be my python version? Perhaps I should just start over. Let me know if you have any ideas. I hate to waste your time. I have access to an openBSD server that I may try installing this on. My problem there is that I usually have to set the python path in the application. (or I just dont know how to set it on openBSD yet. ) --- David Fraser <da...@sj...> wrote: > Greenbeard wrote: > > >Hello there > > > >I am running Win2k, Python 2.2, on Apache2 , mod_py > >3.0.1 > > > >I extracted the archive to site-packages and > changed > >the httpd.conf as shown in your homepage. I get: > >----------------------------------------------- > >Mod_python error: "PythonHandler jToolkit.web" > > > >Traceback (most recent call last): > > > > File "C:\Python22\Lib\mod_python\apache.py", line > >335, in HandlerDispatch > > result = object(req) > > > > File > >"C:\Python22\Lib\site-packages\jToolkit\web\__init__.py", > >line 72, in handler > > instance = getattr(module, instancename) > > > >AttributeError: 'module' object has no attribute > >'HelloWorldConfig' > > > >----------------------------------------------- > >Here is httpd.conf > > > > <Directory "C:/Program Files/Apache > >Group/Apache2/htdocs/jtoolkit"> > >SetHandler python-program > >PythonHandler jToolkit.web > >PythonOption jToolkit.module > jToolkit.demo.helloworld > >PythonOption jToolkit.instance HelloWorldConfig > >PythonDebug On > > > ></Directory> > > > > > >TIA, > > > >gb400 > > > > > Hi > > Thanks for reporting this, this shouldn't happen, > but hopefully we'll be > able to track it down... > I have attached a modified version of > jToolkit\web\__init__.py (this is > now in jToolkit CVS). > You should be able to save it over the __init__.py > in > C:\Python22\Lib\site-packages\jToolkit\web\__init__.py > > This should give you a more detailed error message > saying which > attributes are present in the imported module: > > Mod_python error: "PythonHandler jToolkit.web" > > Traceback (most recent call last): > > File > "/usr/local/python22nothreads/lib/python2.2/site-packages/mod_python/apache.py", > line 193, in Dispatch > result = object(req) > > File > "/share/sjsoft/code/jSuite.py/jToolkit/web/__init__.py", > line 84, in handler > server = getserver(modulename, instancename) > > File > "/share/sjsoft/code/jSuite.py/jToolkit/web/__init__.py", > line 69, in getserver > raise AttributeError("module %r has no attribute > %r\nmodule is %r, attributes are %r" % (modulename, > instancename, module, dir(module))) > > AttributeError: module 'jToolkit.demo.helloworld' > has no attribute 'HelloWorldConfIg' > module is <module 'jToolkit.demo.helloworld' from > '/share/sjsoft/code/jSuite.py/jToolkit/demo/helloworld.pyc'>, > attributes are ['HelloWorldConfig', > 'HelloWorldServer', '__builtins__', '__doc__', > '__file__', '__name__', 'server', 'widgets'] > Python path is ['/share/sjsoft/code/jSuite.py/', > '/usr/local/python22nothreads/lib/python2.2/', > '/usr/local/python22nothreads/lib/python2.2/site-packages'] > > Something else that might be helpful is to try the > following from python: > from jToolkit.demo import helloworld > dir(helloworld) > print helloworld.HelloWorldConfig > > Let me know the results you find! Thanks for helping > to test the package > > Regards > David > > PS Soon jToolkit should have the ability to run in a > standalone mode > without mod_python or Apache, which should make > testing and initial > setup easier > > > """jToolkit.web package index and master handler > function for mod_python""" > > # Copyright 2002, 2003 St James Software > # > # This file is part of jToolkit. > # > # jToolkit is free software; you can redistribute it > and/or modify > # it under the terms of the GNU General Public > License as published by > # the Free Software Foundation; either version 2 of > the License, or > # (at your option) any later version. > # > # jToolkit is distributed in the hope that it will > be useful, > # but WITHOUT ANY WARRANTY; without even the implied > warranty of > # MERCHANTABILITY or FITNESS FOR A PARTICULAR > PURPOSE. See the > # GNU General Public License for more details. > # > # You should have received a copy of the GNU General > Public License > # along with jToolkit; if not, write to the Free > Software > # Foundation, Inc., 59 Temple Place, Suite 330, > Boston, MA 02111-1307 USA > > import sys > > # list of modules in this package > __all__ = ["safeapache", "server", "session"] > > # the global list of application servers, used to > remember the server based on the fullinstancename > # one server per instance defined in the > configuration > servers = {} > > logtimes = 0 > > if logtimes: > import os, time > try: > import thread > except ImportError: > # pretend we have threads if we don't > def thread_get_ident(): > return 0 > class blank: pass > thread = blank() > thread.get_ident = thread_get_ident > logfilename = '/tmp/threads.log' > > def logtime(message): > osid = os.getpid() > threadid = thread.get_ident() > t = time.time() > ms = int((t - int(t))*1000.0) > timestr = time.strftime('%Y-%m-%d %H:%M:%S') + > '.%03d' % ms > f = open(logfilename, 'a') > f.write('%s: pid %r tid %r: %s\n' % (timestr, > osid, threadid, message)) > f.close() > else: > def logtime(message): > """don't log anything as we aren't in logtimes > mode""" > pass > > def getserver(modulename, instancename): > """returns a server based on a given instance in a > given module""" > fullinstancename = modulename + "." + instancename > if fullinstancename in servers: > server = servers[fullinstancename] > else: > # this is equivalent to: from modulename import > instancename > try: > module = __import__(modulename, globals(), > locals(), [instancename]) > except ImportError, importmessage: > errormessage = "Error importing module %r: > %s\nPython path is %r" \ > % (modulename, importmessage, > sys.path) > raise ImportError(errormessage) > # get the actual instance > try: > instance = getattr(module, instancename) > except AttributeError: > errormessage = "module %r has no attribute > %r\nmodule is %r, attributes are %r\nPython path is > %r" \ > % (modulename, instancename, > module, dir(module), sys.path) > raise AttributeError(errormessage) > # construct a server of the appropriate class > using the instance > server = instance.serverclass(instance) > server.name = fullinstancename > servers[fullinstancename] = server > return server > > # handler is in here so that we can say > PythonHandler jToolkit.web > # (modpython automatically looks for handler in that > module) > def handler(req): > """the standard handler which locates the > instance, creates the server if neccessary, and > hands off to it""" > logtime('handler start: ' + req.uri) > apache_options = req.get_options() > modulename = apache_options['jToolkit.module'] > instancename = apache_options['jToolkit.instance'] > server = getserver(modulename, instancename) > pathwords = filter(None, req.uri.split('/')) # > split into bits, strip out empty strings > logtime('calling server.handle: ' + req.uri) > thepage = server.handle(req, pathwords) > logtime('calling server.sendpage: ' + req.uri) > result = server.sendpage(req, thepage) > logtime('done: ' + req.uri) > return result > > __________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com |