Weirdness. Re: [mod_python] Help with apache.import_module

donnie donnie at darthik.com
Wed Aug 18 15:32:05 EDT 2004


Alright, more information, haha.

After some investigation, I discovered that if I placed the
module(mymodule.py) in the /var/www then it would load fine, without
having to be loaded in the URL first.

Eventually, I checked out my apache2 configuration, and changed the
Directory to /var/www/python as you can see below, this has solved all
of my problems.  :-)

<Directory /var/www/python>
  AddHandler mod_python .py
  PythonHandler mod_python.publisher
  PythonDebug On
</Directory>

Thanks.

--
Donnie

On Wed, 2004-08-18 at 14:01, donnie wrote:
> Well, I thought I had it completely working...
> I have found that I can only get the module that I am trying to import
> to be found if I load that module through the url:
> http://localhost/python/mymodule.py/mytest
> before trying to access the module in the url:
> http://localhost/python/blah.py/main
> 
> I guess apache can find the module once it has been loaded into memory,
> but is not finding the module if it has not been loaded first?
> This boggles my mind....?
> Thanks.
> 
> --
> Donnie
> 
> On Wed, 2004-08-18 at 13:32, donnie wrote:
> > On Wed, 2004-08-18 at 12:39, donnie wrote:
> > > I am having problems importing a module when using mod_python.
> > > Here is the error I receive...
> > > 
> > > --------begin-----------
> > > Mod_python error: "PythonHandler mod_python.publisher"
> > > 
> > > Traceback (most recent call last):
> > > 
> > >   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
> > >     result = object(req)
> > > 
> > >   File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line 98, in handler
> > >     path=[path])
> > > 
> > >   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 457, in import_module
> > >     module = imp.load_module(mname, f, p, d)
> > > 
> > >   File "/var/www/python/blah.py", line 2, in ?
> > >     mymodule = apache.import_module('mymodule', log=1)
> > > 
> > >   File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 454, in import_module
> > >     f, p, d = imp.find_module(parts[i], path)
> > > 
> > > ImportError: No module named mymodule
> > > ----------end---------
> > > 
> > > This is the file I am executing.
> > > filename: blah.py
> > > --------begin-----------
> > > from mod_python import apache
> > > mymodule = apache.import_module('mymodule', log=1)
> > > 
> > > def main(req):
> > >   num = 100
> > >   blah = mymodule.mytest(num)
> > >   req.write("this is a test, blah = %s" % blah)
> > >   return
> > > ---------end----------
> > > 
> > > Here is the file that contains the module that I am trying to import.
> > > filename: mymodule.py
> > > --------begin----------
> > > def mytest(num):
> > >   blah = num
> > >   return blah
> > > --------end------------
> > > 
> > > I am not sure what I am doing wrong....
> > > The files are located in /var/www/python/
> > > and blah.py is loaded like this: http://localhost/python/blah.py
> > > 
> > > Any help would be greatly appreciated.
> > > I am very new to python and modpython, but I am hooked!
> > > 
> > > Thank you.
> > > 
> > > --
> > > Donnie
> > > 
> > 
> > Well, after testing and testing and trying again and again, I got it to
> > work!  haha... simple errors always get ya. ;-)
> > 
> > First problem, I wasn't calling the function in my url.
> > http://localhost/python/blah.py/main
> > That got the file to load, but mozilla was asking me to save the file
> > b.c it didn't know how to handle the file.
> > 
> > Second problem, I forgot to add:
> > req.content_type = "text/html"
> > req.send_http_header()
> > 
> > Well, hope that helps anyone else in the future.
> > Thanks.
> > 
> > --
> > Donnie
> > 
> > 
> > 
> > 
> > ______________________________________________________________________
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://mailman.modpython.org/mailman/listinfo/mod_python
> 
> ______________________________________________________________________
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://modpython.org/pipermail/mod_python/attachments/20040818/c2aa1223/attachment.bin


More information about the Mod_python mailing list