mapproxy / mapproxy

MapProxy is a tile cache and WMS proxy
http://mapproxy.org
Apache License 2.0
532 stars 251 forks source link

Unable to featch tiles from URL with unicode characters #914

Open Monstrofil opened 3 months ago

Monstrofil commented 3 months ago

Context

I'm trying to setup maproxy to fetch tiles form completely valid url with unicode part in in, but I'm completely stuck.

I set source as following in mapproxy config:

  malodanilivska-orto-10000:
    coverage:
      bbox:
      - 4010367.60886099
      - 6457200.030434674
      - 4050310.0396765363
      - 6478721.177496373
      srs: EPSG:102100
    grid: GLOBAL_WEBMERCATOR
    http:
      ssl_no_cert_checks: true
    type: tile
    url: https://otgportal.com.ua/arcgis/rest/services/hark_malodanulivska/Малоданилівська_орто_10000/MapServer/tile/%(z)s/%(y)s/%(x)s

And I get this error:

[2024-03-30 12:57:44,850] mapproxy.source.request - INFO - GET https://otgportal.com.ua/arcgis/rest/services/hark_malodanulivska/Малоданилівська_орто_10000/MapServer/tile/12/1385/2457 - - 0
[2024-03-30 12:57:44,850] mapproxy.source.tile - WARNING - could not retrieve tile: URL not correct (see logs for URL and reason).

It's obviously related to how urllib works with unicode in urls (spoiler: it does not :)).

But when I tried to change the unicode part with quoted, I got another error:

ValueError: unsupported format character 'D' (0x44) at index 67
  File "/mnt/c/workspace/geoarchive/testprj/.venv/lib/python3.12/site-packages/mapproxy/client/tile.py", line 81, in substitute
    url = self.url_template.substitute(tile_coord, format, self.grid)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/c/workspace/geoarchive/testprj/.venv/lib/python3.12/site-packages/mapproxy/client/tile.py", line 81, in substitute
    return self.template % data
           ~~~~~~~~~~~~~~^~~~~~
ValueError: unsupported format character 'D' (0x44) at index 67
    return self.template % data
           ~~~~~~~~~~~~~~^~~~~~
ValueError: unsupported format character 'D' (0x44) at index 67

And this is where I stuck completely.

Are there any known workarounds for this issue?

Expected Behavior

Tiles url with unicode in it should work.

Actual Behavior

Tiles url with unicode does not work.

Your Environment

walkermatt commented 3 months ago

If you have replace the non-ascii characters in the url with their percent encoded equivalent then I think you will have to escape the percentage characters so they are treated as literal values when string formatting.

https://otgportal.com.ua/arcgis/rest/services/hark_malodanulivska/%%D0%%9C%%D0%%B0%%D0%%BB%%D0%%BE%%D0%%B4%%D0%%B0%%D0%%BD%%D0%%B8%%D0%%BB%%D1%%96%%D0%%B2%%D1%%81%%D1%%8C%%D0%%BA%%D0%%B0_%%D0%%BE%%D1%%80%%D1%%82%%D0%%BE_10000/MapServer/tile/%(z)s/%(y)s/%(x)s