<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div id="appendonsend"></div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi Moritz,</div>
<div style="font-family:Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">Hi Roberta,<br>
<br>
I'm really no expert in this domain, so just doing some educated guessing.<br>
<br>
On 28/09/20 18:37, roberta fagandini wrote:<br>
> <br>
> On 28/09/20 17:51, roberta fagandini wrote:<br>
>> Sorry, maybe I didn't explain myself well because actually, I don't get<br>
>> any error from the php web page, simply the code related to grass is not <br>
>> executed.For instance gsetup.init(gisbase, gisdb, location, mapset) does <br>
>> not create any file in my /tmp/ folder and the print(gscript.gisenv()) <br>
>> is not printed.<br>
>> I checked the import of the grass libraries (print(sys.modules)) and <br>
>> they seem to be correctly imported.<br>
> <br>
> Have you checked your webservers error logs ?<br>
> <br>
> I have already checked and this is the error in the webserver log file<br>
> <br>
> File "importgrass.py", line 82, in <module><br>
>      main()<br>
>    File "importgrass.py", line 71, in main<br>
>      rcfile = gsetup.init(gisbase, gisdb, location, mapset)<br>
>    File "/usr/lib/grass74/etc/python/grass/script/setup.py", line 170, <br>
> in init<br>
>      config_dir = os.path.join(os.getenv('HOME'), config_dirname)<br>
>    File "/usr/lib/python3.6/posixpath.py", line 80, in join<br>
>      a = os.fspath(a)<br>
> TypeError: expected str, bytes or os.PathLike object, not NoneType<br>
<br>
First of all, the importgrass.py you sent only has 72 lines, so I don't <br>
know what the line 82 reference in your above error points to.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">This is simply due to some print that I added to the code before checking the error log. <br>
<br>
But most importantly, I would really recommend that you upgrade to a <br>
newer version of GRASS GIS. Current stable is 7.8. There's been a lot of <br>
improvement in terms of python3 compatibility and maybe this is an issue <br>
that has already been resolved.<br>
<br>
It sounds like an issue with a variable containing a path. Apparently it <br>
is of type NoneType...</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">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?<br>
<br>
<br>
> <br>
> How do you call the python script from PhP?<br>
> <br>
> I tried  both with:<br>
> <?php<br>
>         $command = escapeshellcmd('/usr/bin/python3 importgrass.py ');<br>
>          echo exec($command, $output, $return);<br>
> ?><br>
> <br>
> and<br>
> <br>
> <?php<br>
>         $command = escapeshellcmd('/usr/bin/python3 importgrass.py ');<br>
>          echo system($command, $return);<br>
> ?><br>
> <br>
> and<br>
> <br>
> <?php<br>
>         $intestazione='#!/bin/bash'.PHP_EOL;<br>
>         $command = escapeshellcmd('/usr/bin/python3 importgrass.py ');<br>
>         $myfile = fopen("./tmp/script.sh", "w") or die("Unable to open <br>
> file!");<br>
>         fwrite($myfile, $intestazione);<br>
>         fwrite($myfile, $command);<br>
>         fclose($myfile);<br>
>         echo exec("/bin/sh ./tmp/script.sh", $output, $return);<br>
>         print_r($output);<br>
> ?><br>
> <br>
<br>
What happens when you replace '/usr/bin/python3 importgrass.py ' by, for <br>
example '/usr/bin/grass --version', just to check if other executables <br>
work ?</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">I tried to run <span style="color: rgb(0, 0, 0); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif; background-color: rgb(255, 255, 255); display: inline !important">'/usr/bin/grass
 --version' but I got a similar error:</span></div>
<div class="PlainText"><font color="#000000"><br>
</font></div>
<div class="PlainText"><font color="#000000">File "/usr/bin/grass", line 2005, in <module>
<div>    main()</div>
<div>  File "/usr/bin/grass", line 1804, in main</div>
<div>    grass_config_dir = get_grass_config_dir()</div>
<div>  File "/usr/bin/grass", line 398, in get_grass_config_dir</div>
<div>    directory = os.path.join(os.getenv('HOME'), grass_config_dirname)</div>
<div>  File "/usr/lib/python2.7/posixpath.py", line 70, in join</div>
<div>    elif path == '' or path.endswith('/'):</div>
<div>AttributeError: 'NoneType' object has no attribute 'endswith'</div>
</font><br>
Moritz<br>
</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">Thanks again!</div>
<div class="PlainText">Roberta</div>
</span></font></div>
</body>
</html>