From 40779bcfea8fce9a23c552cf449d25a0971ee329 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 10 Nov 2023 22:11:36 +0100 Subject: fix wrong tile URL being requested This was a leftover from the pydantic migration, which now uses a custom URL type that is no longer just an "alias" for str. Therefore, the {x} placeholders got escaped, which we now need to revert. I'm not super happy with the way this works, but it works so far I guess. --- fietsboek/views/tileproxy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/fietsboek/views/tileproxy.py b/fietsboek/views/tileproxy.py index 999b04f..0264284 100644 --- a/fietsboek/views/tileproxy.py +++ b/fietsboek/views/tileproxy.py @@ -8,10 +8,10 @@ Additionally, this protects the users' IP, as only fietsboek can see it. """ import datetime import logging -import random import threading from itertools import chain from typing import List, Optional +from urllib.parse import quote import requests from pydantic import AnyUrl, TypeAdapter @@ -331,7 +331,13 @@ def tile_proxy(request): LOGGER.debug("Aborted attempt to contact %s due to previous timeouts", provider) raise HTTPGatewayTimeout(f"Avoiding request to {provider}") - url = tile_sources[provider].url.unicode_string().format(x=x, y=y, z=z, s=random.choice("abc")) + url = ( + tile_sources[provider] + .url.unicode_string() + .replace(quote("{x}"), str(x)) + .replace(quote("{y}"), str(y)) + .replace(quote("{z}"), str(z)) + ) # Avoid doing actual requests during tests if url.startswith("http://localhost:0"): LOGGER.debug("Skipping tile proxy request for testing URL") -- cgit v1.2.3