Hi Moritz, Hi Roberta,
I'm really no expert in this domain, so just doing some educated guessing. On 28/09/20 18:37, roberta fagandini wrote: > > 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 First of all, the importgrass.py you sent only has 72 lines, so I don't know what the line 82 reference in your above error points to. This is simply due to some print that I added to the code before checking the error log. But most importantly, I would really recommend that you upgrade to a newer version of GRASS GIS. Current stable is 7.8. There's been a lot of improvement in terms of python3 compatibility and maybe this is an issue that has already been resolved. It sounds like an issue with a variable containing a path. Apparently it is of type NoneType... I tried to upgrade GRASS using the repository ubuntugis unstable but it caused some problems with the installation of postgis. Do you have another solution? > > 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); > ?> > What happens when you replace '/usr/bin/python3 importgrass.py ' by, for example '/usr/bin/grass --version', just to check if other executables work ? I tried to run '/usr/bin/grass --version' but I got a similar error: File "/usr/bin/grass", line 2005, in <module> main() File "/usr/bin/grass", line 1804, in main grass_config_dir = get_grass_config_dir() File "/usr/bin/grass", line 398, in get_grass_config_dir directory = os.path.join(os.getenv('HOME'), grass_config_dirname) File "/usr/lib/python2.7/posixpath.py", line 70, in join elif path == '' or path.endswith('/'): AttributeError: 'NoneType' object has no attribute 'endswith' Moritz Thanks again! Roberta
_______________________________________________ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user