You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Chris Howell <ch...@pyxisinnovation.com> on 2007/08/31 17:42:22 UTC

[users@httpd] Testing Python Mod

Hi All,

So in regards to a follow up on my last post. I found this page at.

http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

Which describes how to get the python mod working for apache and I 
changed it around so that I was no longer trying to access it globally.

My .htaccess file looks like

AddHandler python-program .py
PythonHandler mptest
PythonDebug On

And is found in the same directory as my *.py file.

My httpd.conf file has this entry in it now.

<Directory "C:/Program Files/Apache Software 
Foundation/Apache2.2/htdocs/Test">
AllowOverride FileInfo
</Directory>

When I attempt to access the .py file. I get this message up.

MOD_PYTHON ERROR

ProcessId:      2544
Interpreter:    '192.168.0.42'

ServerName:     '192.168.0.42'
DocumentRoot:   'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs'

URI:            '/Test/mptest.py'
Location:       None
Directory:      'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/Test/'
Filename:       'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/Test/mptest.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'mptest'

Traceback (most recent call last):

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1202, in _process_target
    module = import_module(module_name, path=path)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 304, in import_module
    return __import__(module_name, {}, {}, ['*'])

ImportError: No module named mptest

So I've tried two approaches and I am stumped on both of them. 
I would sincerely appreciate any help. 

Cheers
Chris Howell 
Software Engineer 
the PYXIS Innovation - /Common Ground for Digital Earth 
Kingston Ontario.
/www.pyxisinnovation.com






Re: [users@httpd] Testing Python Mod

Posted by Brian Munroe <br...@gmail.com>.
On 9/4/07, Dragon <dr...@crimson-dragon.com> wrote:

>
> You cannot have any indentation on line 1 of your script as that is
> the top level of coade and must have zero indentation until you enter
> a new code block with a different execution scope.
>
> Anyway, this is not an Apache issue any longer, you should read up on
> python and its syntactical requirements to fix the problem you have now.
>

yep, that will get you every time!

Chris - this is the last I am going to comment on this thread.  I
highly recommend the book Practical Python.  In my opinion, it gives a
great overview of the language and ramps up to more advanced topics at
a very nice pace.

http://hetland.org/writing/practical-python/

Good Luck!

-- brian

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Testing Python Mod

Posted by Dragon <dr...@crimson-dragon.com>.
Chris Howell wrote:

>Yes I have set it up to listen on port 9000 and everything works 
>fine. I fixed the 404 error. This is the error I am getting now.
>
>
>MOD_PYTHON ERROR
>
>ProcessId:      2932
>Interpreter:    '192.168.0.42'
>
>ServerName:     '192.168.0.42'
>DocumentRoot:   'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs'
>
>URI:            '/Test/test.py'
>Location:       None
>Directory:      'C:/Program Files/Apache Software 
>Foundation/Apache2.2/htdocs/Test/'
>Filename:       'C:\\Program Files\\Apache Software 
>Foundation\\Apache2.2\\htdocs\\Test\\test.py'
>PathInfo:       ''
>
>Phase:          'PythonHandler'
>Handler:        'mod_python.publisher'
>
>Traceback (most recent call last):
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 
> 1537, in HandlerDispatch
>     default=default_handler, arg=req, silent=hlist.silent)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 
> 1229, in _process_target
>     result = _execute_target(config, req, object, arg)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 
> 1128, in _execute_target
>     result = object(arg)
>
>   File "C:\Python25\Lib\site-packages\mod_python\publisher.py", 
> line 204, in handler
>     module = page_cache[req]
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 
> 1059, in __getitem__
>     return import_module(req.filename)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 
> 296, in import_module
>     log, import_path)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 
> 680, in import_module
>     execfile(file, module.__dict__)
>
>   File "C:\Program Files\Apache Software 
> Foundation\Apache2.2\htdocs\Test\test.py", line 1
>
>     def world(req):
>
>    ^
>
>IndentationError: unexpected indent
>
>
>MODULE CACHE DETAILS
>
>Accessed:       Tue Sep 04 11:28:20 2007
>Generation:     1
>
>_mp_55aa27656fb6b0a34cdceffae0e6fbab {
>   FileName:     'C:\\Program Files\\Apache Software 
> Foundation\\Apache2.2\\htdocs\\Test\\test.py'
>   Instance:     4 [RELOAD]
>   Generation:   1 [ERROR]
>   Modified:     Tue Sep 04 11:25:29 2007
>   Imported:     Tue Sep 04 11:24:38 2007
>}
---------------- End original message. ---------------------

That is solely a python error. Your python script is not properly 
formatted. In python, white space is significant and code blocks are 
defined by the indentation. BTW, you read the trace back in reverse 
order the last thing listed is the cause of the error, the rest is 
just a trace of the calling stack.

You cannot have any indentation on line 1 of your script as that is 
the top level of coade and must have zero indentation until you enter 
a new code block with a different execution scope.

Anyway, this is not an Apache issue any longer, you should read up on 
python and its syntactical requirements to fix the problem you have now.

Dragon

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Venimus, Saltavimus, Bibimus (et naribus canium capti sumus)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Testing Python Mod

Posted by Chris Howell <ch...@pyxisinnovation.com>.
Chris Howell wrote:
> Brian Munroe wrote:
>> On 9/4/07, Chris Howell <ch...@pyxisinnovation.com> wrote:
>>   
>>
>>   
>>> Brian:
>>> I made the modifications you suggested my httpd conf file now has this
>>> entry in it.
>>>
>>>  LoadModule python_module modules/mod_python.so
>>>
>>>  <Directory "C:/Program Files/Apache Software
>>> Foundation/Apache2.2/htdocs/Test">
>>>     Order deny,allow
>>>     Satisfy all
>>>     AddHandler mod_python .py
>>>     PythonHandler mod_python.publisher
>>>     PythonDebug On
>>>  </Directory>
>>>
>>>  My test.py file looks like.
>>>
>>>      def world(req):
>>>         return "Hello World"
>>>
>>>  When I try to access it like
>>>  http://localhost:9000/Test/test.py/world
>>>
>>>  I get a 404.
>>>
>>>  Any other ideas ?
>>>
>>>     
>>
>> At least you are getting a new kind of error!
>>
>> Well, it isn't exactly like I suggested, but I tried your
>> configuration (you have a 'Listen 9000' in your httpd.conf, right?)
>> and everything worked fine for me.
>>
>> I know this is a pain, but comment out the <Directory> </Directory>
>> related to the mod_python stuff, restart apache and see if you still
>> get the 404 when trying to hit
>>
>> http://localhost:9000/Test/test.py
>>
>> You should get the raw python code rendered in your browser.
>>
>> -- brian
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>   
>
> Brian:
>
> Yes I have set it up to listen on port 9000 and everything works fine. 
> I fixed the 404 error. This is the error I am getting now.
>
> MOD_PYTHON ERROR
>
> ProcessId:      2932
> Interpreter:    '192.168.0.42'
>
> ServerName:     '192.168.0.42'
> DocumentRoot:   'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs'
>
> URI:            '/Test/test.py'
> Location:       None
> Directory:      'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/Test/'
> Filename:       'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Test\\test.py'
> PathInfo:       ''
>
> Phase:          'PythonHandler'
> Handler:        'mod_python.publisher'
>
> Traceback (most recent call last):
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
>     default=default_handler, arg=req, silent=hlist.silent)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1229, in _process_target
>     result = _execute_target(config, req, object, arg)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1128, in _execute_target
>     result = object(arg)
>
>   File "C:\Python25\Lib\site-packages\mod_python\publisher.py", line 204, in handler
>     module = page_cache[req]
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1059, in __getitem__
>     return import_module(req.filename)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 296, in import_module
>     log, import_path)
>
>   File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 680, in import_module
>     execfile(file, module.__dict__)
>
>   File "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Test\test.py", line 1
>
>     def world(req):
>
>    ^
>
> IndentationError: unexpected indent
>
>
> MODULE CACHE DETAILS
>
> Accessed:       Tue Sep 04 11:28:20 2007
> Generation:     1
>
> _mp_55aa27656fb6b0a34cdceffae0e6fbab {
>   FileName:     'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Test\\test.py'
>   Instance:     4 [RELOAD]
>   Generation:   1 [ERROR]
>   Modified:     Tue Sep 04 11:25:29 2007
>   Imported:     Tue Sep 04 11:24:38 2007
> }
>
>> I suspect it's related to the format of my .py file, so I am in the process of addressing it at that avenue right now. 
>>   
>
> Cheers
> Chris
>>   
>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.485 / Virus Database: 269.13.3/986 - Release Date: 9/3/2007 9:31 AM
>   
Brian:

Finally got it working thanks so MUCH for your help.

Cheers
Chris Howell
Software Engineer
chowell@pyxisinnovation.com
the PYXIS innovation - /Common Ground for Digital Earth
/Kingston, Ontario
w: www.pyxisinnovation.com



Re: [users@httpd] Testing Python Mod

Posted by Chris Howell <ch...@pyxisinnovation.com>.
Brian Munroe wrote:
> On 9/4/07, Chris Howell <ch...@pyxisinnovation.com> wrote:
>   
>
>   
>> Brian:
>> I made the modifications you suggested my httpd conf file now has this
>> entry in it.
>>
>>  LoadModule python_module modules/mod_python.so
>>
>>  <Directory "C:/Program Files/Apache Software
>> Foundation/Apache2.2/htdocs/Test">
>>     Order deny,allow
>>     Satisfy all
>>     AddHandler mod_python .py
>>     PythonHandler mod_python.publisher
>>     PythonDebug On
>>  </Directory>
>>
>>  My test.py file looks like.
>>
>>      def world(req):
>>         return "Hello World"
>>
>>  When I try to access it like
>>  http://localhost:9000/Test/test.py/world
>>
>>  I get a 404.
>>
>>  Any other ideas ?
>>
>>     
>
> At least you are getting a new kind of error!
>
> Well, it isn't exactly like I suggested, but I tried your
> configuration (you have a 'Listen 9000' in your httpd.conf, right?)
> and everything worked fine for me.
>
> I know this is a pain, but comment out the <Directory> </Directory>
> related to the mod_python stuff, restart apache and see if you still
> get the 404 when trying to hit
>
> http://localhost:9000/Test/test.py
>
> You should get the raw python code rendered in your browser.
>
> -- brian
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>   

Brian:

Yes I have set it up to listen on port 9000 and everything works fine. I 
fixed the 404 error. This is the error I am getting now.

MOD_PYTHON ERROR

ProcessId:      2932
Interpreter:    '192.168.0.42'

ServerName:     '192.168.0.42'
DocumentRoot:   'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs'

URI:            '/Test/test.py'
Location:       None
Directory:      'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/Test/'
Filename:       'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Test\\test.py'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'mod_python.publisher'

Traceback (most recent call last):

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1128, in _execute_target
    result = object(arg)

  File "C:\Python25\Lib\site-packages\mod_python\publisher.py", line 204, in handler
    module = page_cache[req]

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1059, in __getitem__
    return import_module(req.filename)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 296, in import_module
    log, import_path)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 680, in import_module
    execfile(file, module.__dict__)

  File "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Test\test.py", line 1

    def world(req):

   ^

IndentationError: unexpected indent


MODULE CACHE DETAILS

Accessed:       Tue Sep 04 11:28:20 2007
Generation:     1

_mp_55aa27656fb6b0a34cdceffae0e6fbab {
  FileName:     'C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\Test\\test.py'
  Instance:     4 [RELOAD]
  Generation:   1 [ERROR]
  Modified:     Tue Sep 04 11:25:29 2007
  Imported:     Tue Sep 04 11:24:38 2007
}


> I suspect it's related to the format of my .py file, so I am in the process of addressing it at that avenue right now. 
>   

Cheers
Chris
>
>   


Re: [users@httpd] Testing Python Mod

Posted by Brian Munroe <br...@gmail.com>.
On 9/4/07, Chris Howell <ch...@pyxisinnovation.com> wrote:
>

> Brian:
> I made the modifications you suggested my httpd conf file now has this
> entry in it.
>
>  LoadModule python_module modules/mod_python.so
>
>  <Directory "C:/Program Files/Apache Software
> Foundation/Apache2.2/htdocs/Test">
>     Order deny,allow
>     Satisfy all
>     AddHandler mod_python .py
>     PythonHandler mod_python.publisher
>     PythonDebug On
>  </Directory>
>
>  My test.py file looks like.
>
>      def world(req):
>         return "Hello World"
>
>  When I try to access it like
>  http://localhost:9000/Test/test.py/world
>
>  I get a 404.
>
>  Any other ideas ?
>

At least you are getting a new kind of error!

Well, it isn't exactly like I suggested, but I tried your
configuration (you have a 'Listen 9000' in your httpd.conf, right?)
and everything worked fine for me.

I know this is a pain, but comment out the <Directory> </Directory>
related to the mod_python stuff, restart apache and see if you still
get the 404 when trying to hit

http://localhost:9000/Test/test.py

You should get the raw python code rendered in your browser.

-- brian

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Testing Python Mod

Posted by Chris Howell <ch...@pyxisinnovation.com>.
Brian Munroe wrote:
> On 8/31/07, Chris Howell <ch...@pyxisinnovation.com> wrote:
>
>   
>>  AddHandler python-program .py
>>  PythonHandler mptest
>>  PythonDebug On
>>
>>     
>
> Chris:
>
> I would suggest you use the Publisher mod_python handler, at least to
> get started.
>
> Here is a simple hello, world in mod_python.  I assume you fixed your
> other problem with mod_python from yesterday?  Let me guess, reinstall
> everything? :)
>
> In my httpd.conf file, in a global scope.
>
> LoadModule python_module modules/mod_python.so
> AddHandler mod_python .py
> PythonHandler mod_python.publisher
> PythonDebug On
>
> Then inside of my DocumentRoot (default is htdocs), I have a file
> called hello.py that looks like:
>
> def world(req):
> 	return "hello, world"
>
> Then finally, I access it via:
>
> http://localhost/hello.py/world
>
> which renders "hello, world" in plain text to the browser.
>
> -- brian
>
> PS.  Don't cross-post to lists, you are going to get flamed by the moderators!
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
>
> Brian:
     I made the modifications you suggested my httpd conf file now has 
this entry in it.
 
LoadModule python_module modules/mod_python.so

<Directory "C:/Program Files/Apache Software 
Foundation/Apache2.2/htdocs/Test">
   Order deny,allow
   Satisfy all
   AddHandler mod_python .py
   PythonHandler mod_python.publisher
   PythonDebug On
</Directory>


My test.py file looks like.

    def world(req):
       return "Hello World"       

When I try to access it like
http://localhost:9000/Test/test.py/world

I get a 404.

Any other ideas ?




Re: [users@httpd] Testing Python Mod

Posted by Brian Munroe <br...@gmail.com>.
On 8/31/07, Chris Howell <ch...@pyxisinnovation.com> wrote:

>
>  AddHandler python-program .py
>  PythonHandler mptest
>  PythonDebug On
>

Chris:

I would suggest you use the Publisher mod_python handler, at least to
get started.

Here is a simple hello, world in mod_python.  I assume you fixed your
other problem with mod_python from yesterday?  Let me guess, reinstall
everything? :)

In my httpd.conf file, in a global scope.

LoadModule python_module modules/mod_python.so
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On

Then inside of my DocumentRoot (default is htdocs), I have a file
called hello.py that looks like:

def world(req):
	return "hello, world"

Then finally, I access it via:

http://localhost/hello.py/world

which renders "hello, world" in plain text to the browser.

-- brian

PS.  Don't cross-post to lists, you are going to get flamed by the moderators!

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org