xeus icon indicating copy to clipboard operation
xeus copied to clipboard

%load doesn't work as hoped on https

Open stonebig opened this issue 3 years ago • 5 comments

Trying to get this to work

%load  https://raw.githubusercontent.com/MicrosoftDocs/mslearn-introduction-to-machine-learning/main/graphing.py 

I get an error:

/tmp/xeus-python-kernel/envs/xeus-python-kernel/lib/python3.10/urllib/request.py in unknown_open(self, req)
   1417     def unknown_open(self, req):
   1418         type = req.type
-> 1419         raise URLError('unknown url type: %s' % type)
   1420 
   1421 def parse_keqv_list(l):

URLError: <urlopen error unknown url type: https>

is it a limitation ? is there a simple workaround ? (via javascript alternative ?)

stonebig avatar Dec 27 '22 16:12 stonebig

ok, found there the mother jupyterlite issue .. which is a pyodide temporary limitation https://github.com/jupyterlite/jupyterlite/issues/919

suggestion one made is:

from js import fetch

suggestion two is:

import pyodide_http
pyodide_http.patch_all()

stonebig avatar Dec 27 '22 16:12 stonebig

would it be possible to include pyodide-http ?

image

maybe it's a temporary workaround, so don't know if it's sane to be done.

stonebig avatar Dec 27 '22 17:12 stonebig

Your last two comments are very specific to pyodide, unfortunately that won't help in the case of xeus-python.

We will probably need a mock module for urllib/request similar to what we did for requests in https://github.com/emscripten-forge/requests-wasm-polyfill. Maybe a new https://github.com/emscripten-forge/urllib-wasm-polyfill package which uses a similar approach. Maybe @DerThorsten have thought about this before?

martinRenou avatar Jan 02 '23 09:01 martinRenou

Using the latest jupyterlite-xeus version, you can now install the requests package and use it:

name: xeus-kernels
channels:
  - https://repo.mamba.pm/emscripten-forge
  - conda-forge
dependencies:
  - xeus-python
  - requests

martinRenou avatar Feb 14 '24 15:02 martinRenou

Though %load is still not working because it uses urlllib

martinRenou avatar Feb 14 '24 15:02 martinRenou