Skip to content
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

Unable to featch tiles from URL with unicode characters #914

Open
Monstrofil opened this issue Mar 30, 2024 · 1 comment
Open

Unable to featch tiles from URL with unicode characters #914

Monstrofil opened this issue Mar 30, 2024 · 1 comment

Comments

@Monstrofil
Copy link

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

  • Version used: latest master branch
  • Environment name and version (e.g. Python 2.7.5 with mod_wsgi 4.5.9): python3.11
  • Server type and version: ubuntu
@walkermatt
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants