Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!-- Changed by tibia.sh in 2026. See "About this copy" in README.md. -->
# Changelog

## Unreleased

- Send the `tibiawikisql/<version> (+https://github.com/tibia-sh/tibiawiki-sql)` User-Agent with every TibiaWiki API
request. Before, requests carried the `requests` library's default, `python-requests/<version>`.

## 9.0.0+tibiash.8

- Retry a TibiaWiki API request that gets no response within 60 seconds, a response cut short mid-body, a 429 or 5xx
Expand Down
11 changes: 11 additions & 0 deletions tests/tests_wikiapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import requests

from tests import load_resource
from tibiawikisql import __version__
from tibiawikisql.api import Article, WikiClient, WikiEntry, Image
from tibiawikisql.errors import WikiApiError

Expand Down Expand Up @@ -313,3 +314,13 @@ def test_images_info_stops_after_retry_budget(self):
self.assertEqual(context.exception.status, 502)
self.assert_requests(5)
self.assertEqual(self.sleep.call_args_list, [call(5), call(15), call(30), call(60)])

def test_requests_carry_the_user_agent(self):
client = WikiClient()

request = client.session.prepare_request(requests.Request("GET", WikiClient.ENDPOINT))

self.assertEqual(
request.headers["User-Agent"],
f"tibiawikisql/{__version__} (+https://github.com/tibia-sh/tibiawiki-sql)",
)
3 changes: 2 additions & 1 deletion tibiawikisql/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class WikiClient:
ENDPOINT: ClassVar[str] = f"{BASE_URL}/api.php"

headers: ClassVar[dict[str, str]]= {
"User-Agent": f'tibiawikisql/{__version__}', # noqa: Q000
"User-Agent": f"tibiawikisql/{__version__} (+https://github.com/tibia-sh/tibiawiki-sql)",
}

def __init__(self, sleep: Callable[[float], None] = time.sleep) -> None:
Expand All @@ -104,6 +104,7 @@ def __init__(self, sleep: Callable[[float], None] = time.sleep) -> None:

"""
self.session = requests.Session()
self.session.headers.update(self.headers)
self._sleep = sleep

def _get_json(self, params: dict) -> dict:
Expand Down
Loading