Skip to content
Snippets Groups Projects
Commit 3625fefd authored by Eva Bardou's avatar Eva Bardou :frog: Committed by Yoann Schneider
Browse files

Define a custom `User-Agent` in the `_retried_request` helper

parent e26f79d8
No related tags found
1 merge request!621Define a custom `User-Agent` in the `_retried_request` helper
Pipeline #209007 passed
import importlib.metadata
import logging
logging.basicConfig(
......@@ -5,3 +6,5 @@ logging.basicConfig(
format="%(asctime)s %(levelname)s/%(name)s: %(message)s",
)
logger = logging.getLogger(__name__)
VERSION = importlib.metadata.version("arkindex-base-worker")
......@@ -27,7 +27,7 @@ from tenacity import (
wait_exponential,
)
from arkindex_worker import logger
from arkindex_worker import VERSION, logger
from arkindex_worker.utils import pluralize
from teklia_toolbox.requests import should_verify_cert
......@@ -41,6 +41,8 @@ DOWNLOAD_TIMEOUT = (30, 60)
BoundingBox = namedtuple("BoundingBox", ["x", "y", "width", "height"])
# Specific User-Agent to bypass potential server limitations
IIIF_USER_AGENT = f"Teklia/Workers {VERSION}"
# To parse IIIF Urls
IIIF_URL = re.compile(r"\w+:\/{2}.+\/.+\/.+\/.+\/(?P<size>.+)\/!?\d+\/\w+\.\w+")
# Full size of the region
......@@ -339,7 +341,12 @@ def _retry_log(retry_state, *args, **kwargs):
)
def _retried_request(url, *args, method=requests.get, **kwargs):
resp = method(
url, *args, timeout=DOWNLOAD_TIMEOUT, verify=should_verify_cert(url), **kwargs
url,
*args,
headers={"User-Agent": IIIF_USER_AGENT},
timeout=DOWNLOAD_TIMEOUT,
verify=should_verify_cert(url),
**kwargs,
)
resp.raise_for_status()
return resp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment