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
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ History
* The version is now retrieved from package metadata at runtime using
``importlib.metadata``. This reduces the chance of version inconsistencies
during releases.
* The async client now builds its ``Authorization`` header with
``aiohttp.encode_basic_auth()`` instead of the ``aiohttp.BasicAuth`` /
``auth=`` parameter, which are deprecated as of aiohttp 3.14.0. As a result,
the minimum required ``aiohttp`` version is now 3.14.0.

5.2.0 (2025-11-20)
++++++++++++++++++
Expand Down
10 changes: 8 additions & 2 deletions src/geoip2/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,14 @@ async def insights(self, ip_address: IPAddress = "me") -> Insights:
async def _session(self) -> aiohttp.ClientSession:
if not hasattr(self, "_existing_session"):
self._existing_session = aiohttp.ClientSession(
auth=aiohttp.BasicAuth(self._account_id, self._license_key),
headers={"Accept": "application/json", "User-Agent": _AIOHTTP_UA},
headers={
"Accept": "application/json",
"Authorization": aiohttp.encode_basic_auth(
self._account_id,
self._license_key,
),
Comment on lines +359 to +362
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If account_id is passed as bytes to the client, self._account_id will be stored as bytes (as seen in BaseClient.__init__). Passing a bytes object to aiohttp.encode_basic_auth will result in an incorrect Authorization header because the f-string formatting inside aiohttp.encode_basic_auth will format it as b'...' (e.g., b'12345':license_key), leading to authentication failures.

We should decode self._account_id to a string if it is a bytes object before passing it to aiohttp.encode_basic_auth.

                    "Authorization": aiohttp.encode_basic_auth(
                        self._account_id.decode("utf-8")
                        if isinstance(self._account_id, bytes)
                        else self._account_id,
                        self._license_key,
                    ),

"User-Agent": _AIOHTTP_UA,
},
timeout=aiohttp.ClientTimeout(total=self._timeout),
)

Expand Down
Loading