[GRASS-user] R: exwcuting grass python script from php web page
roberta fagandini
robifagandini at hotmail.it
Mon Sep 28 09:37:30 PDT 2020
On 28/09/20 17:51, roberta fagandini wrote:
> Sorry, maybe I didn't explain myself well because actually, I don't get
> any error from the php web page, simply the code related to grass is not
> executed.For instance gsetup.init(gisbase, gisdb, location, mapset) does
> not create any file in my /tmp/ folder and the print(gscript.gisenv())
> is not printed.
> I checked the import of the grass libraries (print(sys.modules)) and
> they seem to be correctly imported.
Have you checked your webservers error logs ?
I have already checked and this is the error in the webserver log file
File "importgrass.py", line 82, in <module>
main()
File "importgrass.py", line 71, in main
rcfile = gsetup.init(gisbase, gisdb, location, mapset)
File "/usr/lib/grass74/etc/python/grass/script/setup.py", line 170, in init
config_dir = os.path.join(os.getenv('HOME'), config_dirname)
File "/usr/lib/python3.6/posixpath.py", line 80, in join
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
How do you call the python script from PhP?
I tried both with:
<?php
$command = escapeshellcmd('/usr/bin/python3 importgrass.py ');
echo exec($command, $output, $return);
?>
and
<?php
$command = escapeshellcmd('/usr/bin/python3 importgrass.py ');
echo system($command, $return);
?>
and
<?php
$intestazione='#!/bin/bash'.PHP_EOL;
$command = escapeshellcmd('/usr/bin/python3 importgrass.py ');
$myfile = fopen("./tmp/script.sh", "w") or die("Unable to open file!");
fwrite($myfile, $intestazione);
fwrite($myfile, $command);
fclose($myfile);
echo exec("/bin/sh ./tmp/script.sh", $output, $return);
print_r($output);
?>
Are you sure that your web server has sufficient permissions to access
the relevant directories ?
Yes, I'm pretty sure! If I run the python script from terminal as www-data it works perfectly.
Moritz
Thanks!
Roberta
> ------------------------------------------------------------------------
> *Da:* Moritz Lennert <mlennert at club.worldonline.be>
> *Inviato:* lunedì 28 settembre 2020 17:29
> *A:* roberta fagandini <robifagandini at hotmail.it>;
> grass-user at lists.osgeo.org <grass-user at lists.osgeo.org>
> *Oggetto:* Re: [GRASS-user] exwcuting grass python script from php web page
> On 28/09/20 12:10, roberta fagandini wrote:
>> Hi all!
>> I wrote a python script with grass to be run from a php web page.
>> The python script works perfectly if I run it from the terminal but when
>> I try to run it from the php web page, the grass related part seems to
>> be ignored and the grass session is not launched. I set the grass gis
>> environment following this link [0].
>> From the php side, I try to launch the python script using both exec(),
>> system() and also a bash script to run the python script but I always
>> got the same error.
>
> Maybe you could tell us what error you get ?
>
> Moritz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20200928/adbe0ff4/attachment.html>
More information about the grass-user
mailing list