banesullivan / localtileserver

🌐 dynamic tile server for visualizing rasters in Jupyter with ipyleaflet or folium
https://localtileserver.banesullivan.com
MIT License
304 stars 29 forks source link

get_folium_tile_client failing with a 500 status error #144

Closed JosephKuchar closed 1 year ago

JosephKuchar commented 1 year ago

Hi again,

For testing I wanted to try to get localtileserver installed on my local machine. I have a fresh installation of Ubuntu, Anaconda, and a conda environment with no packages installed besides localtileserver, jupyter and folium (and their dependencies through conda).

When I try to run the example

from localtileserver import get_folium_tile_layer, TileClient, examples
from folium import Map

client = examples.get_oam2()  # use example data

t = get_folium_tile_layer(client)

m = Map(location=client.center(), zoom_start=16)
m.add_child(t)
m

I get the following error:

[2023-04-25 14:50:09,396] ERROR in app: Exception on /api/metadata [GET]
Traceback (most recent call last):
  File "/home/joseph/anaconda3/envs/mapping/lib/python3.11/site-packages/flask/app.py", line 1517, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joseph/anaconda3/envs/mapping/lib/python3.11/site-packages/flask/app.py", line 1503, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)

 ...

  File "/home/joseph/anaconda3/envs/mapping/lib/python3.11/site-packages/large_image_source_gdal/__init__.py", line 184, in __init__
    self._setDefaultStyle()
  File "/home/joseph/anaconda3/envs/mapping/lib/python3.11/site-packages/large_image_source_gdal/__init__.py", line 294, in _setDefaultStyle
    self.style = {'bands': style}
    ^^^^^^^^^^
AttributeError: property 'style' of 'GDALFileTileSource' object has no setter

(abbreviated, let me know if the whole error is essential). There's also an HTTP error associated with it,

HTTPError                                 Traceback (most recent call last)
Cell In[1], line 9
      6 client = examples.get_oam2()  # use example data
      8 # Create folium tile layer from that server
----> 9 t = get_folium_tile_layer(client)
     11 m = Map(location=client.center(), zoom_start=16)
     12 m.add_child(t)

...

File ~/anaconda3/envs/mapping/lib/python3.11/site-packages/localtileserver/client.py:843, in get_or_create_tile_client(source, port, debug, default_projection)
    841 try:
    842     r = requests.get(source.create_url("api/metadata"))
--> 843     r.raise_for_status()
    844 except requests.HTTPError as e:
    845     # Make sure to destroy the server and its thread if internally created.
    846     if _internally_created:

File ~/anaconda3/envs/mapping/lib/python3.11/site-packages/requests/models.py:1021, in Response.raise_for_status(self)
   1016     http_error_msg = (
   1017         f"{self.status_code} Server Error: {reason} for url: {self.url}"
   1018     )
   1020 if http_error_msg:
-> 1021     raise HTTPError(http_error_msg, response=self)

HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: http://127.0.0.1:37371/api/metadata?&filename=%2Fvsicurl%3Furl%3Dhttps%253A%252F%252Foin-hotosm.s3.amazonaws.com%252F59c66c5223c8440011d7b1e4%252F0%252F7ad397c0-bba2-4f98-a08a-931ec3a6e943.tif%26use_head%3Dno%26list_dir%3Dno

Based on this error, it looks like flask is failing to make a local webpage to host the tiles (if I understand how opentileserver works).

I also experienced this on my Windows machine, I'm sure there's something obvious I'm neglecting. Thanks!

--------------------------------------------------------------------------------
  Date: Tue Apr 25 14:55:11 2023 EDT

                     OS : Linux
                 CPU(s) : 4
                Machine : x86_64
           Architecture : 64bit
                    RAM : 7.5 GiB
            Environment : Jupyter
            File system : ext4

  Python 3.11.3 | packaged by conda-forge | (main, Apr  6 2023, 08:57:19) [GCC
  11.3.0]

        localtileserver : 0.6.4
                  flask : 2.1.3
          flask_caching : 1.10.1
             flask_cors : 3.0.10
            flask_restx : 1.0.6
               requests : 2.28.2
               werkzeug : 2.1.2
                  click : 8.1.3
          server_thread : 0.2.0
                 scooby : 0.7.1
            large_image : 1.20.5
large_image_source_gdal : 1.20.4
             cachetools : 5.3.0
                    PIL : 9.5.0
                 psutil : 5.9.5
                  numpy : 1.24.3
             palettable : 3.3.3
                 pyproj : 3.5.0
             osgeo.gdal : 3.6.4
              traitlets : 5.9.0
                 folium : 0.14.0
--------------------------------------------------------------------------------
banesullivan commented 1 year ago

In your report, you have large_image : 1.20.5 and large_image_source_gdal : 1.20.4. These need to match. Update large_image_source_gdal to fix the issue

The problematic change was in https://github.com/girder/large_image/pull/1121. I should have had the GDAL source limit large_image on that release.

banesullivan commented 1 year ago

Or I guess the version is limited in the PyPI wheel but not on the conda-forge recipe, hence this issue.

JosephKuchar commented 1 year ago

That did it, thanks! I appreciate the help.