Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

using Inline Python with CGI

by garima3003 (Initiate)
on Jun 12, 2019 at 07:43 UTC ( #11101266=perlquestion: print w/replies, xml ) Need Help??

garima3003 has asked for the wisdom of the Perl Monks concerning the following question:

I was going through a post on http://codeverge.com/perl.inline/running-inline-python-in-a-cgi-script/741065

Unfortunately i ended up getting into the same situation.
I am new to perl and python and through a cgi calling a perl script and python code is embedded in Perl script.

Tried the same code but still no luck.
Below is the code :

#---------------------------- # Defining The constants #--------------------------- *SUBMIT = \'submit'; *TRUE = \1; *FALSE = \0; *DISABLED = \'DISABLED'; sub store_policy() { print "Started\n"; use Inline::Python qw(py_new_object py_call_method); use Inline Python => 'DATA', DIRECTORY => '/usr/local/webmin/gehc_password_management/_Inli +ne/'; Inline->init(); print "\nGoing to create Object\n"; my $obj = py_new_object("gehc_password_management","gehc_password_mana +gement","passwordManagement"); #print "hello".py_call_method($obj,"testPrint")."\n"; print("\nCreated the Object"); #my $flag = $obj->getPasswordConfigFilePath(); #print($flag); print "\nClosed"; } 1; # Return true, required for libraries __DATA__ __Python__ from passwordChangeNew import PasswordManagement as passwordManagement
and getting the below error:
Started HTTP/1.0 500 Perl execution failed Server: MiniServ/1.840 Date +: Tue, 11 Jun 2019 22:58:49 GMT Content-type: text/html; Charset=iso- +8859-1 Connection: close Error - Perl execution failed Marker '__Python__ from passwordChangeNew import PasswordManagement as + passwordManagement ' does not match Inline 'Python' section.at ./pol +icy-lib.pl line 36.
Can somebody please help ?

Need it as asap

Replies are listed 'Best First'.
Re: using Inline Python with CGI
by Corion (Pope) on Jun 12, 2019 at 08:16 UTC

    The Inline::Python documentation shows the following approach to using it:

    use Inline Python; ... __END__ __Python__ Python source code goes here.

    In the past, I had problems with the weirdo option parsing that Inline uses, so maybe if the above approach works for you, you need to play around with the order of the options?

    The error message sounds a bit weird - it seems that Inline sees the complete DATA section as one line. Maybe insert some more newlines and make sure that the newline style used in your Perl code matches the newline style in your Python code?! Maybe you have trailing whitespace (or Windows newlines?!) at the end of the __Python__ string and Inline doesn't know how to treat that?

      Thanks for the quick response @Corion But that doesn't seem to a problem for us. We tried that as well.
Re: using Inline Python with CGI
by hippo (Canon) on Jun 12, 2019 at 08:06 UTC

    Welcome to the Monastery, garima3003. You wrote:

    I am new to perl and python

    If I were new to 2 separate languages I doubt that the first thing I would do when faced with a task would be to try to use both unfamiliar languages and some unfamiliar glue to join them together. Is there some reason you wouldn't prefer to use just perl or (heaven forfend) just python to achieve your task, whatever that might be? Surely concentrating on just one language would help, especially since you appear to "Need it as asap".

Re: using Inline Python with CGI
by bliako (Priest) on Jun 13, 2019 at 12:55 UTC

    Here is the relevant piece of code causing the complaint (M09_marker_mismatch()) from Inline

    sub read_DATA { require Socket; my ($marker, $marker_tag); my $o = shift; my ($pkg, $language_id) = @{$o->{API}}{qw(pkg language_id)}; unless ($DATA_read{$pkg}++) { no strict 'refs'; *Inline::DATA = *{$pkg . '::DATA'}; local ($/); my ($CR, $LF) = (&Socket::CR, &Socket::LF); (my $data = <Inline::DATA>) =~ s/$CR?$LF/\n/g; @{$DATA{$pkg}} = split /(?m)^[ \t]{0,}(__\S+?__\n)/, $data; shift @{$DATA{$pkg}} unless ($ {$DATA{$pkg}}[0] || '') =~ /__\ +S+?__\n/; } ($marker, $o->{API}{code}) = splice @{$DATA{$pkg}}, 0, 2; croak M08_no_DATA_source_code($language_id) unless defined $marker; ($marker_tag = $marker) =~ s/__(\S+?)__\n/$1/; croak M09_marker_mismatch($marker, $language_id) unless $marker_tag eq $language_id; }

    first line below asks the system what is CR and what is LF and then replaces code-line endings with a \n and then splits the code to lines. If you are willing to add debugging lines in Inline.pm in the section with the above sub, or start by making sure your system's CR and LF are some valid characters.

    my ($CR, $LF) = (&Socket::CR, &Socket::LF); (my $data = <Inline::DATA>) =~ s/$CR?$LF/\n/g; @{$DATA{$pkg}} = split /(?m)^[ \t]{0,}(__\S+?__\n)/, $data;

    I would follow Corion's hint on CR/LF - what editor did you use to type in your perl script? what system are you on?

      We are doing it through Cygwin terminal and its a windows 10 machine

        I'm tempted just to link to Re^2: manipulating a data table.

        Why? Why this ammount of pure pain?

        • Scary operating system that you don't want to run a server on - CHECK
        • Emulating a completely different operating system family - CHECK
        • ... in user space - CHECK
        • Using two languages with probably the most opposite philosopies (TIMTOWTDI vs. TOOWTDI) in the same program - CHECK
        • ... when both support the common gateway interface (CGI) out of the box(1) - CHECK
        • Using the slowest possible interface (CGI) to the webserver - CHECK
        • ... despite both languages and most common webservers supporting FastCGI(2) - CHECK
        • ... despite both languages supporting integration into the webserver (mod_perl, mod_python) - CHECK

        What is wrong with you?

        Among collegues, I would ask if your domina has become too weak ...

        Alexander


        (1) Perl did so, for a long time. In very recent versions, you have to install CGI via CPAN.

        (2) FastCGI: See also Re: CGI or CGI::Fast, Re^9: mod_perl, and weird caching

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        all alarm lights blinking then

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://11101266]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2019-06-25 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (107 votes). Check out past polls.

    Notices?