Inconsistencies between Grist Desktop and Server

I’m evaluating Grist as an alternative to Excel spreadsheets with lots of macros. I often need to verify lists of servers, network devices, and IP addresses. I enrich these lists with additional data from network services like DNS or REST APIs which should be fairly easy to access from Python.

I was able to accomplish my goals in a test environment on a Linux server. In my production environment though, I’m limited to a VDI workstation running Windows 10. The results I’m getting from Grist server and Grist desktop don’t match. Some of this I understand, but I’m still looking for a solution that works for Grist desktop.

The first inconsistency involves the Python standard library. I added the following formula to a column:

import socket

return socket.gethostbyname($Hostname)

The results from gethostbyname on the server are correct. The results from the same formula on desktop are not. I’m getting IPs returned like 172.29.1.0, 172.29.2.0, 172.29.3.0, and 172.29.4.0. If this is some kind of sandbox for Grist desktop, is there a way to disable it, so Python will make a call to my DNS server instead of returning these sequential network IPs?

The second inconsistency involves adding Python libraries. I need the requests library to make REST API calls from Python. On the server version, I found the venv Grist is using in the sandbox_venv3 directory. I just added the requests library through pip, and the following Python formula works great:

import requests

ip = $IP
url = f'https://ipinfo.io/{ip}/json
res = requests.get(url, timeout=10)
return res.json()['hostname']

I found the topic How to add Python libs in Grist Desktop? from February. As a followup to the last post in that thread, is it possible to point Grist desktop at a local venv, so I can add custom libs to Python? Would a local venv also address the first issue, or is that unrelated?

Thanks!

Hi @Alan, yes there is sandboxing on by default in the desktop app. You can turn it off if working with trusted documents.

See the unsandboxed setting for GRIST_SANDBOX_FLAVOR:

After I set the environment variable GRIST_SANDBOX_FLAVOR to unsandboxed and started Grist Desktop.exe, the formula with gethostbyname returned the correct results. Thanks for that!

I found a venv I thought Grist Desktop was using installed at C:\Program Files\Grist Desktop\resources\app.asar.unpacked\core\sandbox_venv3. I manually ran the Python there and used pip to install the requests module. My formula with requests.get works when running python.exe interactively from this directory, but I still get the ModuleNotFoundError : No module named 'requests' error when I run my formula inside Grist Desktop. Any ideas?

Not a developer, but this thread/post may help? Python requests package - #14 by paul-grist

Thank you both! I set the following variables and values in the Windows 10 user environment variables for my account:

GRIST_SANDBOX_FLAVOR=unsandboxed
GRIST_ENABLE_REQUEST_FUNCTION=1

after restarting Grist Desktop, both of these formulas work correctly:

gethostbyname

import socket
return socket.gethostbyname($Hostname) 

REQUEST

ip = $IP
res = REQUEST(f'https://ipinfo.io/{ip}/json')
return res.json()['hostname']

Thanks again!

1 Like