diff --git a/packages/python/examples/metrics_django/metrics_django/settings.py b/packages/python/examples/metrics_django/metrics_django/settings.py index 3809ea9398..269da566b8 100644 --- a/packages/python/examples/metrics_django/metrics_django/settings.py +++ b/packages/python/examples/metrics_django/metrics_django/settings.py @@ -132,7 +132,7 @@ api_key=os.getenv("README_API_KEY"), grouping_function="metrics.views.grouping_function", background_worker_mode=False, - base_log_url="https://docs.readme.com" + # base_log_url="https://example.com", buffer_length=1, timeout=5, ) diff --git a/packages/python/readme_metrics/GetProjectBaseUrl.py b/packages/python/readme_metrics/GetProjectBaseUrl.py index 95c9661e3a..dae589764e 100644 --- a/packages/python/readme_metrics/GetProjectBaseUrl.py +++ b/packages/python/readme_metrics/GetProjectBaseUrl.py @@ -1,18 +1,24 @@ import requests, base64 from functools import lru_cache +from urllib.parse import urljoin def auth(readme_api_key: str): - encodedAuth = base64.b64encode("%s:" % readme_api_key) + encodedAuth = base64.b64encode(f"{readme_api_key}:") return {"Authorization": "Basic %s" % encodedAuth} -@lru_cache(maxsize = 512) +@lru_cache(maxsize=None) def get_project_base_url(readme_api_url: str, readme_api_key: str): - url = "%s/v1" % readme_api_url + + url = urljoin(readme_api_url, "/v1") headers = auth(readme_api_key) - project = requests.get(url, headers=headers).json() - return project.baseUrl + try: + response = requests.get(url, headers=headers, timeout=1) + response.raise_for_status() + return response.baseUrl + except: + return "" diff --git a/test/integration-metrics.test.js b/test/integration-metrics.test.js index 613da430f0..248291c24e 100644 --- a/test/integration-metrics.test.js +++ b/test/integration-metrics.test.js @@ -197,7 +197,7 @@ describe('Metrics SDK Integration Tests', function () { expect(response.content.mimeType).toMatch(/application\/json(;\s?charset=utf-8)?/); }); - it.only('should include an _id UUID in har payload', async function () { + it('should include an _id UUID in har payload', async function () { await fetch(`http://localhost:${PORT}`, { method: 'get' }); const [, body] = await getRequest();