-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: module 'urllib.request' has no attribute 'HTTPSHandler' when using astropy #33
Comments
Thanks for the kind words! Your example makes it easier to find the problem. Let me figure out of we can patch it and ignore the |
That would be super cool. Do you need help? Also, the example https://github.com/koenvo/pyodide-http/blob/main/examples/pyvo.html returns the same error because pyvo is using astropy. |
Still trying to reproduce the issue. The example Could it be a different pyodide version? When loading it shows version pyodide-0.22.1. When I try this code it also works fine in Chrome/FireFox and Safari: <html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<py-config>
packages = ["ssl", "pyodide-http>=0.2.1", "astropy"]
</py-config>
<py-script>
import pyodide_http
pyodide_http.patch_all()
from astropy.coordinates import SkyCoord
res = SkyCoord.from_name("Crab Nebula")
print(res)
</py-script>
</body>
</html> output <SkyCoord (ICRS): (ra, dec) in deg
(83.6287, 22.0147)> |
The example works for me too now with pyscript ✨ 🦀 ⭐ Then the issue might be more on jupyterlite side? On the question of the pyodide version, in the cds-astro/jupyterlite there is the jupyterlite-pyodide-kernel v0.0.8. It looks like they are using pyodide 0.23.2 ? : |
Thanks both for looking into this!
Right, So it could indeed be related to the Pyodide version. |
Just checked with the Pyodide console directly and it is giving the same error. Although an extra The console also runs |
I think requests >>> import micropip
>>> await micropip.install(["requests==2.29.0", "ssl", "pyodide-http>=0.2.1", "astropy"])
>>> import pyodide_http; pyodide_http.patch_all()
>>> from astropy.coordinates import SkyCoord
>>> res = SkyCoord.from_name("Crab Nebula")
>>> res
<SkyCoord (ICRS): (ra, dec) in deg
(83.6287, 22.0147)> So there should probably be a range of compatible |
Hmm I tried to use requests The pyodide I suspect it to be something with a different python version instead of a different requests version. [edit]
|
Yeah, you are right it can't be that. Went to the conclusion too quickly )
So indeed in the notebook 04-sesame.ipynb : cds-astro.github.io/jupyterlite/lab/index.html where this is reproducible while in the Pyodide REPL which has exactly same pyodide version would have A plausible scenario is that If I add, from importlib import reload
import http.client
import urllib.request
reload(http.client)
reload(urllib.request) to the above notebook, I would now get,
which is still unclear but at least different from the original error. No idea how the status return code can be 0. |
Because import micropip
await micropip.install(["ssl", "pyodide-http>=0.2.1", "astropy"])
import pyodide_http; pyodide_http.patch_all()
from astropy.coordinates import SkyCoord
res = SkyCoord.from_name("Crab Nebula") in the stable pyodide REPL, I get pyodide.ffi.JsException: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load '[http://cdsweb.u-strasbg.fr/cgi-bin/](http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/A?Crab%20Nebula)
[nph-sesame/A?Crab%20Nebula](http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/A?Crab%20Nebula)'. with the full error message: Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/lib/python3.11/site-packages/astropy/coordinates/sky_coordinate.py", line 2218, in from_name
icrs_coord = get_icrs_coordinates(name, parse, cache=cache)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/astropy/coordinates/name_resolve.py", line 170, in get_icrs_coordinates
download_file(url, cache=cache, show_progress=False)
File "/lib/python3.11/site-packages/astropy/utils/data.py", line 1509, in download_file
f_name = _download_file_from_source(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/astropy/utils/data.py", line 1293, in _download_file_from_source
with _try_url_open(
^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/astropy/utils/data.py", line 1211, in _try_url_open
return urlopener.open(req, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/pyodide_http/_urllib.py", line 58, in urlopen_self_removed
return urlopen(url, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/pyodide_http/_urllib.py", line 31, in urlopen
resp = send(request)
^^^^^^^^^^^^^
File "/lib/python3.11/site-packages/pyodide_http/_core.py", line 121, in send
xhr.send(to_js(request.body))
pyodide.ffi.JsException: NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load '[http://cdsweb.u-strasbg.fr/cgi-bin/](http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/A?Crab%20Nebula)
[nph-sesame/A?Crab%20Nebula](http://cdsweb.u-strasbg.fr/cgi-bin/nph-sesame/A?Crab%20Nebula)'. The console actually reveals that this is a an error from mixing HTTP content on an HTTPS site
In Chrome, one can allow insecure content and doing that, the code runs fine. However, in jupyterlite, even with the So I think we should then just upstream fix this by making an HTTPS request here in |
Thanks for looking! This PR open in astropy is exactly to change the link to sesame to its https version (and other CDS things too) 🙂 But what about the data that don't have a https address? Like for example some old nasa mission? We will never be able to query them through jupyterlite? |
I tried to summarise the issue to better understand what's going on, and came to this summary:
Curious if you come to the same summary. From these issues there are some possible solutions/fixes. When I look at the possibilities at the
To answer @ManonMarchand question about old data: the source needs to support both |
Hi all, It seems like the fix that I proposed earlier in this thread stopped working, because the CORS error that I got here (that we resolved through changing the URL to
So it seems like with newer versions of |
I'm pretty sure it didn't happen in Pyodide, so you probably should report this to JupyterLite. |
It works in pyodide repl with :
But I cannot find any combination of load/reload/patch that makes it work in jupyterlite. So I guess we should open an issue there? |
I found that the issue in A new version of >>> import micropip
>>> await micropip.install(["ssl", "pyodide-http>=0.2.1", "astropy"])
>>> from astropy.coordinates import SkyCoord
>>> import pyodide_http; pyodide_http.patch_all()
>>> SkyCoord.from_name('NGC3256') ). I think this issue here can therefore be closed now. |
Hello and thanks for this library!
I was unsure about where to post this issue but I'm wondering about why pyodide-http does not work with astropy.
Here is a minimal non-working example :
In jupyterlite, the output is like this :
You can have a look at it there in the notebook
04-sesame.ipynb
:https://cds-astro.github.io/jupyterlite/lab/index.html
From there, what I understand is that maybe urllib needs more patching in order to work with astropy? Or is it more an issue that I should post on their side of the story?
Thanks again!
(PS: the example uses a really cool function that outputs the coordinates of any objects for any of their registered names or designations :) )
The text was updated successfully, but these errors were encountered: