Python requests package

Hello, I’ve built a new image installing the request python package following the guide.
I added in the Dockerfile this:

FROM gristlabs/grist
 
RUN \
  apt update && apt install -y openssl && \
  python3 -m pip install geopy requests

When I try to add a formula with this code:

import requests
r = requests.get(f"http://router.project-osrm.org/route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false""")

I get a connection error about a name resolution error !
Is there something I need to do or I missed?

Hi @Alfredo_Ardito. Welcome to the community!

Typically Grist runs formulas in a secure sandbox. This is important if you ever open documents where you don’t fully trust formulas. The sandbox prevents access by formula code to the filesystem or the network. In a self-managed setup, you can run with or without the sandbox. The relevant instructions are at Self-managed Grist - Grist Help Center. We still recommend using the sandbox.

However, for requesting external resources, all is not lost even with sandbox! There is an experimental function REQUEST, which may be used in formulas, but it is disabled by default because it’s hard to use as is, and hard to use efficiently. To enable it, run your server with the environment variable GRIST_EXPERIMENTAL_PLUGINS=1. Its interface is similar to that of requests.get.

It would be great if you can report back if you’ve had success with it, and also your use case. It might help decide when and how to expose this functionality.

2 Likes

Thank you for replying and for the solutions suggested.
I tried to run grist without the sandbox, although you recommend using it, and the formula worked without errors.
I then tried to run grist with the sandbox enabled with the environment variable GRIST_EXPERIMENTAL_PLUGINS=1 but this didn’t work. I got the same connection error.
Now let me explain what I did.
In the docker-compose.yml file I added the GRIST_EXPERIMENTAL_PLUGINS: 1

services:
  grist:
    container_name: gristlab
    restart: unless-stopped
    image: mygrist/grist
    environment:
      PORT: 9999
      GRIST_SANDBOX_FLAVOR: gvisor
      GRIST_PAGE_TITLE_SUFFIX: " - Beta"
      GRIST_EXPERIMENTAL_PLUGINS: 1
    ports:
      - "9999:9999"
    volumes:
      - ./persist:/persist

Is this how I have to setup the docker-compose.yml file?
BTW, do I need to use a custom requests package?
I truly thank you for your time and effort for support us.

Hmm, I expected this would be enough. Do you have logs from the docker container (available via docker logs) that show what happens and what fails when you try to use REQUEST() calls?

yes I’ve done other tests. This is my actual docker-compose.yml file

version: '3.4'

services:
  grist:
    container_name: gristlab
    restart: unless-stopped
    image: agromnia/grist
    environment:
      APP_HOME_URL: 'https://gristlab.example.com'
      PORT: 7799
      GRIST_DEFAULT_EMAIL: 'whatever@whenever.com'
      GRIST_SESSION_SECRET: 'justasecretecode'
      GRIST_SANDBOX_FLAVOR: gvisor
      GRIST_PAGE_TITLE_SUFFIX: " - Beta"
      GRIST_WIDGET_LIST_URL: "https://github.com/gristlabs/grist-widget/releases/download/latest/manifest.json"                                                                                                   
      GRIST_EXPERIMENTAL_PLUGINS: 1
    ports:
      - "7799:7799"
    networks:
      gristlab-network:
        ipv4_address: 172.31.0.2
    volumes:
      - ./persist:/persist

networks:
  gristlab-network:
    driver: bridge
    name: gristlab-network
    ipam:
      config:
        - subnet: 172.31.0.0/16
          gateway: 172.31.0.1

The errors I got are:

An exception of type `ConnectionError` is a subclass of `OSError`.
An `OSError` exception is usually raised by the Operating System
to indicate that an operation is not allowed or that
a resource is not available.

I suspect that you are trying to connect to a server and
that a connection cannot be made.

If that is the case, check for typos in the URL
and check your internet connectivity.

which reports this:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 200, in _new_conn
    sock = connection.create_connection(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 60, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 388, in request
    self.endheaders()
  File "/usr/local/lib/python3.9/http/client.py", line 1280, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/lib/python3.9/http/client.py", line 1040, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.9/http/client.py", line 980, in send
    self.connect()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 236, in connect
    self.sock = self._new_conn()
  File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 207, in _new_conn
    raise NameResolutionError(self.host, self, e) from e
urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x7f2717805a60>: Failed to resolve 'router.project-osrm.org' ([Errno -2] Name or service not known)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 844, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment
    raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type]
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='router.project-osrm.org', port=80): Max retries exceeded with url: /route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f2717805a60>: Failed to resolve 'router.project-osrm.org' ([Errno -2] Name or service not known)"))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/grist/sandbox/grist/engine.py", line 952, in _recompute_one_cell
    result = col.method(record, table.user_table)
  File "usercode", line 475, in A
    r = requests.get(f"http://router.project-osrm.org/route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false""")
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 73, in get
    return request("get", url, params=params, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='router.project-osrm.org', port=80): Max retries exceeded with url: /route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f2717805a60>: Failed to resolve 'router.project-osrm.org' ([Errno -2] Name or service not known)"))

The Docker Logs excerpt :

2023-07-07T19:01:40.316008080Z 2023-07-07 19:01:40.137 - debug: 3-pipe Sandbox started sandboxPid=22, flavor=gvisor, command=undefined, entryPoint=(default)
2023-07-07T19:01:40.338752175Z 2023-07-07 19:01:40.338 - info: Sandbox stderr: run.py: sandbox/gvisor/run.py -E PYTHONPATH=/grist/sandbox/grist -E PIPE_MODE=minimal -m /grist/sandbox --checkpoint /tmp/engine__grist python3 -- /grist/sandbox/grist/main.py sandboxPid=22, flavor=gvisor, command=undefined, entryPoint=(default)
2023-07-07T19:01:45.385369239Z 2023-07-07 19:01:45.384 - info: Sandbox stderr: Ready message: [INFO] [__main__] Ready sandboxPid=22, flavor=gvisor, command=undefined, entryPoint=(default)
2023-07-07T19:01:45.689978628Z 2023-07-07 19:01:45.689 - warn: Sandbox unexpectedly exited with code 0 signal null sandboxPid=22, flavor=gvisor, command=undefined, entryPoint=(default)
2023-07-07T19:01:56.264749020Z Welcome to Grist.
2023-07-07T19:01:56.265092363Z In quiet mode, see http://localhost:7799 to use.
2023-07-07T19:01:56.265100949Z For full logs, re-run with DEBUG=1
2023-07-07T19:01:56.654100847Z 2023-07-07 19:01:56.653 - info: == Grist version is 1.1.2 (commit unknown)
2023-07-07T19:01:56.712432302Z 2023-07-07 19:01:56.712 - debug: skipping incomplete language fa (set GRIST_OFFER_ALL_LANGUAGES if you want it)
2023-07-07T19:01:56.782482314Z 2023-07-07 19:01:56.782 - info: Loading empty config because /persist/config.json missing
2023-07-07T19:01:56.799938804Z 2023-07-07 19:01:56.799 - warn: did not find an appropriately named example workspace in deployment
2023-07-07T19:01:56.803168843Z 2023-07-07 19:01:56.802 - info: No plugins directory: ENOENT: no such file or directory, scandir '/grist/.grist/plugins'
2023-07-07T19:01:56.830376628Z 2023-07-07 19:01:56.830 - info: Found 1 valid plugins on the system
2023-07-07T19:01:56.830545788Z 2023-07-07 19:01:56.830 - debug: PLUGIN builtIn/core -- /grist/plugins/core
2023-07-07T19:01:56.878987294Z 2023-07-07 19:01:56.878 - info: Server timeouts: keepAliveTimeout 305000 headersTimeout 306000
2023-07-07T19:01:56.882643456Z 2023-07-07 19:01:56.882 - info: server(home,docs,static) available at 0.0.0.0:7799
2023-07-07T19:01:56.913377053Z 2023-07-07 19:01:56.913 - info: activity docCount=2, orgCount=0, orgInGoodStandingCount=0, userCount=8, userWithLoginCount=6
2023-07-07T19:01:56.921562006Z 2023-07-07 19:01:56.921 - warn: Failed to create GoogleAuth endpoint: GOOGLE_CLIENT_SECRET is not defined
2023-07-07T19:01:56.926489884Z 2023-07-07 19:01:56.926 - info: == appRoot: /grist
2023-07-07T19:01:56.926735611Z 2023-07-07 19:01:56.926 - info: == i18:namespace: client,server
2023-07-07T19:01:56.926841881Z 2023-07-07 19:01:56.926 - info: == docsRoot: /persist/docs
2023-07-07T19:01:56.926911026Z 2023-07-07 19:01:56.926 - info: == defaultBaseDomain: gristlab.example.com
2023-07-07T19:01:56.926978382Z 2023-07-07 19:01:56.926 - info: == pluginUrl: undefined
2023-07-07T19:01:56.927050643Z 2023-07-07 19:01:56.926 - info: == instanceRoot: /persist
2023-07-07T19:01:56.927123560Z 2023-07-07 19:01:56.927 - info: == tag: unknown
2023-07-07T19:01:56.927202857Z 2023-07-07 19:01:56.927 - info: == database: sqlite:///persist/home.sqlite3
2023-07-07T19:01:56.927285894Z 2023-07-07 19:01:56.927 - info: == userRoot: /grist/.grist
2023-07-07T19:01:56.927336233Z 2023-07-07 19:01:56.927 - info: == loginMiddlewareComment: no-logins
2023-07-07T19:01:56.927396275Z 2023-07-07 19:01:56.927 - info: == docWorkerId: testDocWorkerId_7799
2023-07-07T19:01:56.927838055Z 2023-07-07 19:01:56.927 - info: == grist.access.supportEmail: support@getgrist.com [default] [GRIST_SUPPORT_EMAIL]
2023-07-07T19:01:56.927902083Z 2023-07-07 19:01:56.927 - info: == grist.access.listPublicSites: false [default] [GRIST_LIST_PUBLIC_SITES]
2023-07-07T19:01:56.927959673Z 2023-07-07 19:01:56.927 - info: == grist.locale.offerAllLanguages: - [GRIST_OFFER_ALL_LANGUAGES]
2023-07-07T19:01:56.928009745Z 2023-07-07 19:01:56.927 - info: == grist.login.system.forwardAuth.header: - [GRIST_FORWARD_AUTH_HEADER]
2023-07-07T19:01:56.928066526Z 2023-07-07 19:01:56.928 - info: == grist.login.skipSession: - [GRIST_IGNORE_SESSION]
2023-07-07T19:01:56.928119141Z 2023-07-07 19:01:56.928 - info: == grist.login.forced: - [GRIST_FORCE_LOGIN]
2023-07-07T19:01:56.928177275Z 2023-07-07 19:01:56.928 - info: == grist.externalStorage.minio.bucket: - [GRIST_DOCS_MINIO_BUCKET]
2023-07-07T19:01:56.928215896Z 2023-07-07 19:01:56.928 - info: == grist.externalStorage.disable: - [GRIST_DISABLE_S3]
2023-07-07T19:01:56.928274615Z 2023-07-07 19:01:56.928 - info: == grist.externalStorage.active: false
2023-07-07T19:01:56.928310726Z 2023-07-07 19:01:56.928 - info: == grist.integrations.allowedWebhookDomains: - [ALLOWED_WEBHOOK_DOMAINS]
2023-07-07T19:01:56.928367142Z 2023-07-07 19:01:56.928 - info: == grist.integrations.proxy: - [GRIST_HTTPS_PROXY]
2023-07-07T19:02:43.150443274Z 2023-07-07 19:02:43.150 - debug: Auth[GET]: gristlab.example.com / customHostSession=, method=GET, host=gristlab.example.com, path=/, org=, email=firstname@lastname.com, userId=6, altSessionId=9jzrLhnUGFVKqDrf58isRC
2023-07-07T19:02:43.159350215Z 2023-07-07 19:02:43.159 - debug: Redirecting userId 6 to: https://gristlab.example.com/o/docs/

and

2023-07-07T19:11:47.705952896Z 2023-07-07 19:11:47.705 - info: Sandbox row count access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED, rowCount=294
2023-07-07T19:11:47.709135964Z 2023-07-07 19:11:47.708 - debug: ActiveDoc _applyUserActions returning {actionNum: 6243, retValues: [null], isModification: true} access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED
2023-07-07T19:11:56.127489773Z 2023-07-07 19:11:56.126 - info: Client onMessage '{"reqId":6,"method":"applyUserActions","args":[0,[["UpdateRecord","_grist_Tables... (322 length)' email=firstname@lastname.com, userId=6, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2
2023-07-07T19:11:56.138605112Z 2023-07-07 19:11:56.138 - debug: activeDocMethod access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED, docMethod=applyUserActions
2023-07-07T19:11:56.139068665Z 2023-07-07 19:11:56.138 - debug: ActiveDoc _applyUserActions(Client REDACTED #2, [['UpdateRecord', '_grist_Tables_column', 34, {isFormula: true, formula: 'import requests\r\n' +
2023-07-07T19:11:56.139080090Z   'r = requests.get(f"http://router.project-osrm.org/route/v1/car/... (157 length)'}]]) access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED
2023-07-07T19:11:56.592162364Z 2023-07-07 19:11:56.591 - info: Sandbox stderr: [INFO] [engine] Traceback (most recent call last): sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592230303Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 200, in _new_conn sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592328066Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:     sock = connection.create_connection( sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592426787Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 60, in create_connection sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592478379Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:     for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592537087Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592587500Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:     for res in _socket.getaddrinfo(host, port, family, type, proto, flags): sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592643258Z 2023-07-07 19:11:56.592 - info: Sandbox stderr: socket.gaierror: [Errno -2] Name or service not known sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592690896Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592749432Z 2023-07-07 19:11:56.592 - info: Sandbox stderr: The above exception was the direct cause of the following exception: sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592790622Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592850914Z 2023-07-07 19:11:56.592 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592890969Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 790, in urlopen sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592942027Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:     response = self._make_request( sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.592994890Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 496, in _make_request sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593051027Z 2023-07-07 19:11:56.592 - info: Sandbox stderr:     conn.request( sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593093197Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 388, in request sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593142108Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     self.endheaders() sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593190549Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/http/client.py", line 1280, in endheaders sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593239992Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     self._send_output(message_body, encode_chunked=encode_chunked) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593297596Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/http/client.py", line 1040, in _send_output sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593328290Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     self.send(msg) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593387367Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/http/client.py", line 980, in send sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593431626Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     self.connect() sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593482870Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 236, in connect sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593529906Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     self.sock = self._new_conn() sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593582715Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 207, in _new_conn sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593628272Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     raise NameResolutionError(self.host, self, e) from e sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593680091Z 2023-07-07 19:11:56.593 - info: Sandbox stderr: urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPConnection object at 0x7f2719e0d160>: Failed to resolve 'router.project-osrm.org' ([Errno -2] Name or service not known) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593725671Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593774508Z 2023-07-07 19:11:56.593 - info: Sandbox stderr: The above exception was the direct cause of the following exception: sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593820033Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593871395Z 2023-07-07 19:11:56.593 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593920500Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 486, in send sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.593971095Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:     resp = conn.urlopen( sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594022434Z 2023-07-07 19:11:56.593 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 844, in urlopen sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594081116Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     retries = retries.increment( sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594121504Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594173867Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type] sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594225763Z 2023-07-07 19:11:56.594 - info: Sandbox stderr: urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='router.project-osrm.org', port=80): Max retries exceeded with url: /route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f2719e0d160>: Failed to resolve 'router.project-osrm.org' ([Errno -2] Name or service not known)")) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594280700Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594321192Z 2023-07-07 19:11:56.594 - info: Sandbox stderr: During handling of the above exception, another exception occurred: sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594383783Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594418665Z 2023-07-07 19:11:56.594 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594482268Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "/grist/sandbox/grist/engine.py", line 952, in _recompute_one_cell sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594517878Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     result = col.method(record, table.user_table) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594564826Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "usercode", line 481, in A sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594617553Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     r = requests.get(f"http://router.project-osrm.org/route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false""") sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594668014Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 73, in get sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594716653Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     return request("get", url, params=params, **kwargs) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594765817Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59, in request sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594813499Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     return session.request(method=method, url=url, **kwargs) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594864618Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 589, in request sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594912334Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     resp = self.send(prep, **send_kwargs) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.594963649Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 703, in send sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.595011032Z 2023-07-07 19:11:56.594 - info: Sandbox stderr:     r = adapter.send(request, **kwargs) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.595061393Z 2023-07-07 19:11:56.595 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 519, in send sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.595109643Z 2023-07-07 19:11:56.595 - info: Sandbox stderr:     raise ConnectionError(e, request=request) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.595164741Z 2023-07-07 19:11:56.595 - info: Sandbox stderr: requests.exceptions.ConnectionError: HTTPConnectionPool(host='router.project-osrm.org', port=80): Max retries exceeded with url: /route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false (Caused by NameResolutionError("<urllib3.connection.HTTPConnection object at 0x7f2719e0d160>: Failed to resolve 'router.project-osrm.org' ([Errno -2] Name or service not known)")) sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.595396650Z 2023-07-07 19:11:56.595 - info: Sandbox stderr:  sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.596430194Z 2023-07-07 19:11:56.596 - debug: Sandbox pyCall[apply_user_actions] took 457 ms sandboxPid=99, flavor=gvisor, command=undefined, entryPoint=(default), docId=REDACTED
2023-07-07T19:11:56.600738829Z 2023-07-07 19:11:56.600 - debug: Sharing _doApplyUserActions access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED, actionNum=6244, linkId=0, otherId=0, numDocActions=3, numRows=2, author=firstname@lastname.com, session=9jzrLhnUGFVKqDrf58isRC
2023-07-07T19:11:56.600987037Z 2023-07-07 19:11:56.600 - debug: _doApplyUserActions (Local): stored #0 [0]: ['ModifyColumn', 'CostoOrario', 'A', {formula: 'import requests\r\n' +
2023-07-07T19:11:56.600995230Z   'r = requests.get(f"http://router.project-osrm.org/route/v1/car/... (157 length)'}]
2023-07-07T19:11:56.601065690Z 2023-07-07 19:11:56.601 - debug: _doApplyUserActions (Local): stored #1 [0]: ['UpdateRecord', '_grist_Tables_column', 34, {formula: 'import requests\r\n' +
2023-07-07T19:11:56.601070795Z   'r = requests.get(f"http://router.project-osrm.org/route/v1/car/... (157 length)'}]
2023-07-07T19:11:56.601146820Z 2023-07-07 19:11:56.601 - debug: _doApplyUserActions (Local): stored #2 [0]: ['UpdateRecord', 'CostoOrario', 1, {A: ['E', 'ConnectionError']}]
2023-07-07T19:11:56.605597458Z 2023-07-07 19:11:56.605 - info: Sandbox row count access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED, rowCount=294
2023-07-07T19:11:56.608319135Z 2023-07-07 19:11:56.608 - debug: ActiveDoc _applyUserActions returning {actionNum: 6244, retValues: [null], isModification: true} access=owners, userId=6, email=firstname@lastname.com, age=12, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=REDACTED, counter=2, docId=REDACTED

Ah, it looks like you are trying to use requests.get from the requests module. To clarify what I meant: when you turn on GRIST_EXPERIMENTAL_PLUGINS, what becomes available is a global function named REQUEST, which you can use (without having to import anything) like this:

r = REQUEST("http://api.open-notify.org/iss-now.json")
r.json()

The data engine code is still sandboxed and cannot access the network, and REQUEST is implemented by asking the node process (which is outside the sandbox) to do the fetching.

Opps … I didn’t realize that. I’ll try it the way u suggested. I’ll let u know soon. Thx

Hello, I did two tests:
First test: success - based on REQUEST only

from geopy.geocoders import Nominatim
import time
from pprint import pprint 
from datetime import timedelta
#import request
import json

r = REQUEST(f"http://router.project-osrm.org/route/v1/car/16.8620293,41.1257843;16.4114643,41.1527614?overview=false""")
routes = json.loads(r.content)
route_1 = routes.get("routes")[0]

return route_1

Second test: failed - based on REQUEST with geocode

from geopy.geocoders import Nominatim
import time
from pprint import pprint 
from datetime import timedelta
#import request
import json

app= Nominatim(user_agent="tutorial")
location = app.geocode("{}, italy".format($da.comune)).raw
lon1 = float(location['lon'])
lat1 = float(location['lat'])

return lon1, lat1

With the second test I get an error about GeocoderUnavailable. Obviously this code works if Grist is not sandboxed.

Here’s the Docker logs:

2023-07-11T13:21:02.172737361Z 2023-07-11 13:21:02.172 - info: heartbeat email=firstname@lastname.com, userId=6, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, url=https://gristlab.example.com/o/docs/tMiZ14Es5ZyH/Agromnia/p/30, docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.352221926Z 2023-07-11 13:21:28.351 - info: Client onMessage '{"reqId":39,"method":"applyUserActions","args":[0,[["UpdateRecord","_grist_Table... (1912 length)' email=firstname@lastname.com, userId=6, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1
2023-07-11T13:21:28.367820636Z 2023-07-11 13:21:28.367 - debug: activeDocMethod access=owners, userId=6, email=firstname@lastname.com, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, docId=tMiZ14Es5ZyHvJ7wBs2Neu, docMethod=applyUserActions
2023-07-11T13:21:28.368007335Z 2023-07-11 13:21:28.367 - debug: ActiveDoc _applyUserActions(Client 659834a893ac49cd #1, [['UpdateRecord', '_grist_Tables_column', 512, {isFormula: true, formula: 'from geopy.geocoders import Nominatim\n' +
2023-07-11T13:21:28.368014308Z   'import time\n' +
2023-07-11T13:21:28.368016352Z   'from pprint import pprint \n' +
2023-07-11T13:21:28.368018264Z   'fro... (1677 length)'}]]) access=owners, userId=6, email=firstname@lastname.com, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.481304903Z 2023-07-11 13:21:28.481 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8615f096a0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.486818967Z 2023-07-11 13:21:28.486 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8615f09b80>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784494412Z 2023-07-11 13:21:28.784 - info: Sandbox stderr: [INFO] [engine] Traceback (most recent call last): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784639563Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 200, in _new_conn sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784745012Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:     sock = connection.create_connection( sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784785687Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/util/connection.py", line 60, in create_connection sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784815581Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:     for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784846370Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/socket.py", line 954, in getaddrinfo sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784887368Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:     for res in _socket.getaddrinfo(host, port, family, type, proto, flags): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784921708Z 2023-07-11 13:21:28.784 - info: Sandbox stderr: socket.gaierror: [Errno -2] Name or service not known sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784938871Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784957668Z 2023-07-11 13:21:28.784 - info: Sandbox stderr: The above exception was the direct cause of the following exception: sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.784987897Z 2023-07-11 13:21:28.784 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.785011391Z 2023-07-11 13:21:28.784 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.785043191Z 2023-07-11 13:21:28.785 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 790, in urlopen sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.785064196Z 2023-07-11 13:21:28.785 - info: Sandbox stderr:     response = self._make_request( sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.785094057Z 2023-07-11 13:21:28.785 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 491, in _make_request sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.785112990Z 2023-07-11 13:21:28.785 - info: Sandbox stderr:     raise new_e sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786008121Z 2023-07-11 13:21:28.785 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 467, in _make_request sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786063874Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     self._validate_conn(conn) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786117641Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1092, in _validate_conn sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786145133Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     conn.connect() sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786159418Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 604, in connect sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786196213Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     self.sock = sock = self._new_conn() sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786222204Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 207, in _new_conn sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786240806Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     raise NameResolutionError(self.host, self, e) from e sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786273251Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: urllib3.exceptions.NameResolutionError: <urllib3.connection.HTTPSConnection object at 0x7f8615f094c0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786302755Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786317296Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: The above exception was the direct cause of the following exception: sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786334564Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786372643Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786399112Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 486, in send sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786413581Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     resp = conn.urlopen( sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786433779Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 874, in urlopen sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786447523Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     return self.urlopen( sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786471413Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 874, in urlopen sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786505365Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     return self.urlopen( sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786528324Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 844, in urlopen sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786548811Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     retries = retries.increment( sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786566637Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 515, in increment sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786601618Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     raise MaxRetryError(_pool, url, reason) from reason  # type: ignore[arg-type] sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786631444Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=Bisceglie%2C+italy&format=json&limit=1 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8615f094c0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786646655Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786663707Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: During handling of the above exception, another exception occurred: sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786704103Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786728390Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786745236Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/geopy/adapters.py", line 457, in _request sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786764850Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     resp = self.session.get(url, timeout=timeout, headers=headers) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786782324Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 602, in get sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786799898Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     return self.request("GET", url, **kwargs) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786834491Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 589, in request sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786863867Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     resp = self.send(prep, **send_kwargs) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786878206Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 703, in send sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786895475Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     r = adapter.send(request, **kwargs) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786945276Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 519, in send sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786972999Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:     raise ConnectionError(e, request=request) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.786987738Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: requests.exceptions.ConnectionError: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=Bisceglie%2C+italy&format=json&limit=1 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8615f094c0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787005858Z 2023-07-11 13:21:28.786 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787022175Z 2023-07-11 13:21:28.786 - info: Sandbox stderr: During handling of the above exception, another exception occurred: sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787052094Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787066306Z 2023-07-11 13:21:28.787 - info: Sandbox stderr: Traceback (most recent call last): sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787083307Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:   File "/grist/sandbox/grist/engine.py", line 952, in _recompute_one_cell sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787133144Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:     result = col.method(record, table.user_table) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787173616Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:   File "usercode", line 371, in geolocation sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787193589Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:     location = app.geocode("{}, italy".format(rec.da.comune)).raw sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787215469Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/geopy/geocoders/nominatim.py", line 297, in geocode sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787233310Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:     return self._call_geocoder(url, callback, timeout=timeout) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787268946Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/geopy/geocoders/base.py", line 368, in _call_geocoder sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787300000Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:     result = self.adapter.get_json(url, timeout=timeout, headers=req_headers) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787314296Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/geopy/adapters.py", line 447, in get_json sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787331379Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:     resp = self._request(url, timeout=timeout, headers=headers) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787375583Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:   File "/usr/local/lib/python3.9/site-packages/geopy/adapters.py", line 469, in _request sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787403191Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:     raise GeocoderUnavailable(message) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787406477Z 2023-07-11 13:21:28.787 - info: Sandbox stderr: geopy.exc.GeocoderUnavailable: HTTPSConnectionPool(host='nominatim.openstreetmap.org', port=443): Max retries exceeded with url: /search?q=Bisceglie%2C+italy&format=json&limit=1 (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8615f094c0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")) sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.787424557Z 2023-07-11 13:21:28.787 - info: Sandbox stderr:  sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.793513553Z 2023-07-11 13:21:28.793 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f86105de3a0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.794694655Z 2023-07-11 13:21:28.794 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f86105de550>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.798331149Z 2023-07-11 13:21:28.798 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f86105cc1f0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.799479048Z 2023-07-11 13:21:28.799 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f86105cc3a0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.802507133Z 2023-07-11 13:21:28.802 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f86105d3130>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.803564959Z 2023-07-11 13:21:28.803 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f86105d32e0>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=Bisceglie%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.806973581Z 2023-07-11 13:21:28.806 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8610602070>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.808078645Z 2023-07-11 13:21:28.807 - info: Sandbox stderr: [WARNING] [urllib3.connectionpool] Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x7f8610602220>: Failed to resolve 'nominatim.openstreetmap.org' ([Errno -2] Name or service not known)")': /search?q=%2C+italy&format=json&limit=1 sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.810846708Z 2023-07-11 13:21:28.810 - debug: Sandbox pyCall[apply_user_actions] took 442 ms sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.815508777Z 2023-07-11 13:21:28.815 - debug: Sandbox memory memory=147304448, sandboxPid=548, flavor=gvisor, command=undefined, entryPoint=(default), docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:21:28.819729685Z 2023-07-11 13:21:28.819 - debug: Sharing _doApplyUserActions access=owners, userId=6, email=firstname@lastname.com, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, docId=tMiZ14Es5ZyHvJ7wBs2Neu, actionNum=6293, linkId=0, otherId=0, numDocActions=3, numRows=6, author=firstname@lastname.com, session=9jzrLhnUGFVKqDrf58isRC
2023-07-11T13:21:28.819809358Z 2023-07-11 13:21:28.819 - debug: _doApplyUserActions (Local): stored #0 [0]: ['ModifyColumn', 'TravelExpense', 'geolocation', {formula: 'from geopy.geocoders import Nominatim\n' +
2023-07-11T13:21:28.819814337Z   'import time\n' +
2023-07-11T13:21:28.819816443Z   'from pprint import pprint \n' +
2023-07-11T13:21:28.819818302Z   'fro... (1677 length)'}]
2023-07-11T13:21:28.819875000Z 2023-07-11 13:21:28.819 - debug: _doApplyUserActions (Local): stored #1 [0]: ['UpdateRecord', '_grist_Tables_column', 512, {formula: 'from geopy.geocoders import Nominatim\n' +
2023-07-11T13:21:28.819879061Z   'import time\n' +
2023-07-11T13:21:28.819885873Z   'from pprint import pprint \n' +
2023-07-11T13:21:28.819887719Z   'fro... (1677 length)'}]
2023-07-11T13:21:28.819958749Z 2023-07-11 13:21:28.819 - debug: _doApplyUserActions (Local): stored #2 [0]: ['BulkUpdateRecord', 'TravelExpense', [1, 2, 3, 4, 5], {geolocation: [['E', 'GeocoderUnavailable'], ['E', 'GeocoderUnavailable'], ['E', 'GeocoderUnavailable'], ['E', 'GeocoderUnavailable'], ['E', 'GeocoderUnavailable']]}]
2023-07-11T13:21:28.823633506Z 2023-07-11 13:21:28.823 - info: Sandbox row count access=owners, userId=6, email=firstname@lastname.com, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, docId=tMiZ14Es5ZyHvJ7wBs2Neu, rowCount=295
2023-07-11T13:21:28.825255308Z 2023-07-11 13:21:28.825 - debug: ActiveDoc _applyUserActions returning {actionNum: 6293, retValues: [null], isModification: true} access=owners, userId=6, email=firstname@lastname.com, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, docId=tMiZ14Es5ZyHvJ7wBs2Neu
2023-07-11T13:22:14.173961635Z 2023-07-11 13:22:14.173 - info: heartbeat email=firstname@lastname.com, userId=6, age=16, org=docs, altSessionId=9jzrLhnUGFVKqDrf58isRC, clientId=659834a893ac49cd, counter=1, url=https://gristlab.example.com/o/docs/tMiZ14Es5ZyH/Agromnia/p/30, docId=tMiZ14Es5ZyHvJ7wBs2Neu

I guess this makes sense. REQUEST function is implemented completely differently because with sandboxing on, the Python code really has no access to the network. But a library like geopy doesn’t know about the Grist-specific REQUEST function.

@alexmojaki , do you think it may be possible to expose this experimental functionality at a lower level where a library like this could use it? geopy in particular supports several adapters for fetching, so it may be possible to make this one work by writing a REQUEST-based adapter, but that’s substantial work for a very narrow solution.

Hello, I did other tests and found, googling, an interesting method to retrieve the latitude and longitude coordinates of various cities using just grist REQUEST without the need of using the library geopy. The only side affect of this method is its slowness when retrieving the latitude and longitude, but it works.
Credit goes to:

How to Retrieve Latitude and Longitude using Python’s Requests Library and OpenStreetMap Nominatim API? | by Siva | Medium

import json

headers = {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
    "accept-language": "en-US,en;q=0.8",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "sec-ch-ua": "\"Brave\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
    "sec-ch-ua-mobile": "?1",
    "sec-ch-ua-platform": "\"Android\"",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "none",
    "sec-fetch-user": "?1",
    "sec-gpc": "1",
    "upgrade-insecure-requests": "1",
    "cookie": "_osm_totp_token=114327"
}


data = [{"state":"MD","city":"Baltimore","country":"usa"},
{"state":"MI","city":"Highland","country":"usa"},
{"state":"SC","city":"Sumter","country":"usa"}
];

semicolon =""  
lonlat=""

for row in data:
    # Remove parentheses and state abbreviation (if present) from the city name
    city = (row['city']).split("(")[0].strip().rstrip(", MA") # example MA
    state = (row['state']).split("(")[0].strip()
    country = (row['country']).split("()")[0].strip()

    url = f"https://nominatim.openstreetmap.org/search.php?city={city}&state={state}&country={country}&format=jsonv2&addressdetails=1&limit=1"
    response = REQUEST(url, headers=headers)
    data = response.json()
    if data:
        # Extract the latitude and longitude from the first result
        lat = float(data[0]["lat"])
        lon = float(data[0]["lon"])
        lonlat += "{}{},{}".format(semicolon, lon, lat)
        semicolon=";"

if not lonlat:
  return None
  
r = REQUEST(f"http://router.project-osrm.org/route/v1/car/{lonlat}?overview=false""")
routes = json.loads(r.content)
route_1 = routes.get("routes")[0]

return route_1

If there’s a better solution I’d be glad to try it out.

REQUEST

Please can you explain how to use REQUEST efficiently?

1 Like

Hi, I’ve been using this code to geolocate and calculate the driving distance between 2 or more cities. This code used to work since a couple of days ago but after upgrading Grist to ver. 1.1.3 it doesn’t work anymore and it throws this error:

HTTPError: Error: REQUEST is not enabled

the working code before upgrading is:

import json
import time
from datetime import timedelta

if not $da.id or not $a.id:
  if len($route.comune)<2:
    return [0,None, None]

headers = {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
    "accept-language": "en-US,en;q=0.8",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "sec-ch-ua": "\"Brave\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
    "sec-ch-ua-mobile": "?1",
    "sec-ch-ua-platform": "\"Android\"",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "none",
    "sec-fetch-user": "?1",
    "sec-gpc": "1",
    "upgrade-insecure-requests": "1",
    "cookie": "_osm_totp_token=114327"
}

if $route and len($route.comune)>1:
  data = []
  for i in $route.comune:
    data.append({"state":"", "city":i,"country":"italy"})
else:
  data = [
    {"state":"","city":$da.comune,"country":"italy"},
    {"state":"","city":$a.comune,"country":"italy"},
  ];

semicolon =""  
lonlat=""

for row in data:
    # Remove parentheses and state abbreviation (if present) from the city name
    city = (row['city']).split("(")[0].strip().rstrip(", MA") # example MA
    state = (row['state']).split("(")[0].strip()
    country = (row['country']).split("()")[0].strip()

    url = f"https://nominatim.openstreetmap.org/search.php?city={city}&state={state}&country={country}&format=jsonv2&addressdetails=1&limit=1"
    response = REQUEST(url, headers=headers)
    data = response.json()
    if data:
        # Extract the latitude and longitude from the first result
        lat = float(data[0]["lat"])
        lon = float(data[0]["lon"])
        # Add the city, latitude, and longitude to the results list
        lonlat += "{}{},{}".format(semicolon, lon, lat)
        semicolon=";"

if not lonlat:
  return None
  
r = REQUEST(f"http://router.project-osrm.org/route/v1/car/{lonlat}?overview=false""")
routes = json.loads(r.content)
route_1 = routes.get("routes")[0]

seconds = round(route_1['duration'])
driving_distance = round(route_1['distance']/1000)

td = timedelta(seconds=seconds)
duration = str(td)

totalhours=round(seconds/3600+.5)

if $ar:
  driving_distance *= 2 

return [totalhours,duration, driving_distance]

I’ve set GRIST_EXPERIMENTAL_PLUGINS=1. Is there anything new I need to do to enable the REQUEST module?

2 Likes

Hello dmitry, after upgrading to grist 1.1.3 the REQUEST function doesn’t work anymore even though I set the GRIST_EXPERIMENTAL_PLUGINS=1. It throws this error:

HTTPError: Error: REQUEST is not enabled

Any clue on how to enable the REQUEST function?

@John1 made some improvements to REQUEST here:

As part of this work, REQUEST became more powerful, and also more of a special case in terms of security. So it is now enabled separately to experimental plugins with:

GRIST_ENABLE_REQUEST_FUNCTION=1

Please do review the description of this flag in the grist-core README before enabling:

enables the REQUEST function. This function performs HTTP requests in a similar way to requests.request. This function presents a significant security risk, since it can let users call internal endpoints when Grist is available publicly. This function can also cause performance issues. Unset by default.

3 Likes