flexxui / flexx

Write desktop and web apps in pure Python
http://flexx.readthedocs.io
BSD 2-Clause "Simplified" License
3.27k stars 259 forks source link

Error 404 on leaflet.py example #741

Closed Galeras14 closed 10 months ago

Galeras14 commented 11 months ago

Hi I created a web-app based on the leaflet.py example. It has worked fine for several years but after a few month since I did not use (Jan 2023), I get a "urllib.error.HTTPError: HTTP Error 404: Not Found".

So, I got back to the leaflet.py code from flexx readthedocs and test it as is --> the example return the same error.

What has change since the beginning of the year that makes this example to stop working ?

Thanks for any help,

almarklein commented 11 months ago

I can reproduce that it does not work. The first exception is when the script tries to obtain https://cdnjs.cloudflare.com/ajax/libs/leaflet//1.0.3/images/marker-icon.png. However, it works fine when I copy-paste that link in the browser. Same for https://cdnjs.cloudflare.com/ajax/libs/leaflet//1.0.3/leaflet.js when I comment the lines that downloads the icons.

So it may be related to the user agent - perhaps leaflet is trying to prevent non-browsers from using the API

jrversteegh commented 11 months ago

It looks like it needs an "Accept-Encoding" header.

wget https://cdnjs.cloudflare.com/ajax/libs/leaflet//1.0.3/images/marker-icon.png

doesn't work, but

wget --header='Accept-Encoding: gzip, deflate, br' https://cdnjs.cloudflare.com/ajax/libs/leaflet//1.0.3/images/marker-icon.png

does.

almarklein commented 11 months ago

Thanks @jrversteegh, that explains it, and I manage to get the example working again in #742.

@Galeras14 Could you please check whether #742 fixes it for you to?

Galeras14 commented 11 months ago

Hi, thanks a lot for your help. However I'm still having trouble. I get this error message from _get data function:

assert res.ok, f"{res.status_code}: {res.reason}" AssertionError: 404: Not Found

In addition, I'm now having a warning message:

/Users/admin/PycharmProjects/Genealogie/env/lib/python3.7/site-packages/urllib3/init.py:38: NotOpenSSLWarning: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 exceptions.NotOpenSSLWarning,

Not sure if it is Mac environment or if it is because I'm using Python 3.8.

almarklein commented 11 months ago

Is that the system Python 3.8? Have you tried upgrading to the latest urllib3 using e.g. pip install -U urllib3?

Galeras14 commented 11 months ago

Yes, I'm in the latest version of urllib3, 2.0.7

Galeras14 commented 11 months ago

I've kind of solve the issue of urllib3 following #3020 issue on urllib3. Still, the leaflet.py example give me this error, even we the suggested modifications:

Traceback (most recent call last): File "/Users/admin/PycharmProjects/Genealogie/sample/ui/essai.py", line 82, in flx.assets.add_shared_data(icon, _get_data('images/%s' % icon)) File "/Users/admin/PycharmProjects/Genealogie/sample/ui/essai.py", line 53, in _get_data assert res.ok, f"{res.status_code}: {res.reason}" AssertionError: 404: Not Found

almarklein commented 10 months ago

Mmm. It's pretty annoying that leaflet produces a 404, and not a more meaningful error code. This way there is no way to see whether the problem is the header or your wifi being down 😕

I tried #742 and I got the same error. It looks like I was trying out some stuff and pushed the wrong version. I updated that PR to the version that works for me too. Sorry for that!

edited: I initially linked to the wrong pr above because of a typo, which I now fixed

Galeras14 commented 10 months ago

With your modification, the example works for me and my app works again. Thanks a lot !