Fwd: Running Inline::Python in a CGI script

[email protected] (Chris Nighswonger)
Newsgroups perl.inline
Message-ID <CAP3yOon3d2_P+fRXGNduS7mKZAARFfa4DmDEwV6r0e9O2FrcLg@mail.gmail.com>
Forgot to 'reply all'... sorry.

---------- Forwarded message ----------
From: Chris Nighswonger <[email protected]>
Date: Tue, Mar 12, 2013 at 9:53 AM
Subject: Re: Running Inline::Python in a CGI script
To: Stefan Seifert <[email protected]>


On Tue, Mar 12, 2013 at 9:43 AM, Stefan Seifert <[email protected]> wrote:

> On Monday 11 March 2013 11:20:36 Chris Nighswonger wrote:
>
> > 2.The second version imports a class from a Python module. The script
> > runs fine when called from the cli. However, it borks when executed as
> > a cgi, complaining of calls to undefined functions/methods. Of course,
> > those functions/methods are in the Python module.
>
> Can you post the script code? Or at least the part dealing with Python?
>

See the Perl script below. The Python module may be seen here:
http://svn.pykota.com/pykota/trunk/pykota/config.py



> When importing Inline::Python it loads and runs the given Python code
> (containing the import statements). Then it inspects the main namespace and
> imports those names into the Perl namespace. I suspect that miniserv.pl
> trickery leads to namespace problems. So could you please try the
> py_new_object() and py_call_function() way of accessing Python? This avoids
> namespace magic and should be more reliable:
>
> # create a Python foo.Bar object and make it look like a Bar object in
> Perl:
> my $bar = py_new_object('Bar', 'foo', 'Bar', 'constructor arg 1');
> $bar->baz();
>

I'll try this and post back the results.

Kind Regards,
Chris

----------

#!/usr/bin/perl

use strict;
use warnings;

BEGIN {
    push(@INC, "..");
};


use Inline  Python      => 'DATA',
            DIRECTORY   => '/usr/share/webmin/pykota/.Inline/';

Inline->init();

my $pykota_conf = new PykotaConfig('/etc/pykota/');
print "Admin mail for the AP400N: " . $pykota_conf->getAdminMail('AP400N')
. "\n";

1;

__DATA__
__Python__

from pykota.config import PyKotaConfig as PykotaConfig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.