Troubleshooting JSON:API / JupyterLite

Continuing the troubleshooting discussion from Share your JupyterLite Examples:

Issue: Executing the JupyterLite example “animal_csv_import.ipynb” causes an
OSError: Request for https://localhost/api/taxonomy_term/animal_type failed with status 500: 500 Service unavailable (with message)

The traceback log of “animal_csv_import.ipynb” in JupyterLite reports a failure in /lib/python3.9 (the Pyolite kernel of JupyterLite?), but a few lines below there is a reference to python 3.8 which is my default python installation. Is there a conflict?

File /lib/python3.9/site-packages/pyodide/http.py:139, in FetchResponse.json(self, **kwargs)
    133 async def json(self, **kwargs) -> Any:
    134     """Return the response body as a Javascript JSON object.
    135 
    136     Any keyword arguments are passed to `json.loads
    137     <https://docs.python.org/3.8/library/json.html#json.loads>`_.
    138     """
--> 139     self._raise_if_failed()

@Symbioquine I’m one step further now. If I remove the bold part below from the HTTP request, then it works. Do you have an idea what the root cause might be?

curl -k ‘https://localhost/api/taxonomy_term/animal_type’ -X POST -H ‘User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0’ -H ‘Accept: /’ -H ‘Accept-Language: de,en-US;q=0.7,en;q=0.3’ -H ‘Accept-Encoding: gzip, deflate, br’ -H ‘Referer: https://localhost/jupyterlite/lab/index.html’ -H ‘Content-type: application/vnd.api+json’ -H ‘X-CSRF-Token: —OMITTED—’ -H ‘Origin: https://localhost’ -H ‘Connection: keep-alive’ -H ‘Cookie: —OMITTED—; jupyterliteDrupalBasePath=/’ -H ‘Sec-Fetch-Dest: empty’ -H ‘Sec-Fetch-Mode: cors’ -H 'Sec-Fetch-Site: same-origin’ --data-raw ‘{“data”: {“type”: “taxonomy_term–animal_type”, “attributes”: {“name”: “Sheep”}}}’

2 Likes

I don’t see anything obviously wrong. That’s an interesting clue about removing those headers, but I don’t have a ready hypothesis about why those would be a problem. I just checked and my requests (which are working) also include similar headers to those.

Are you willing to share your NGINX reverse proxy configuration?

2 Likes

@Symbioquine I’m curious. Here is the nginx.conf :

events {}
http {
  server {
      listen 80 default_server;
      listen [::]:80 default_server;
      server_name _;
      return 301 https://$host$request_uri;
  }
  server {
    server_name localhost;
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/openssl.crt;
    ssl_certificate_key /etc/nginx/ssl/openssl.key;
    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_buffer_size 128k;
      proxy_buffers 4 256k;
      proxy_busy_buffers_size 256k;
      proxy_pass http://www;
    }
  }
}

I followed exactly the description of configuring Local HTTPS here:

1 Like

I removed SSL / HTTPS. No change. :frowning:

Problem solved! :slight_smile:
Solution: JSON API resp. JupyterLite can be used only, if no user is concurrently logged in in FarmOS.

Solution: JSON API resp. JupyterLite can be used only, if no user is concurrently logged in in FarmOS.

Hmmm, that’s strange. I just did a bit of testing and I can’t reproduce that behavior. (I tested with multiple separate users and the same user from a separate browser session while re-running the example in JupyterLite which retrieves/creates the animal taxonomy - it worked every time.)

1 Like