Skip to content

Commit fc59ea6

Browse files
authored
Merge pull request #386 from maxmind/greg/stf-604
Use aiohttp.encode_basic_auth() instead of deprecated BasicAuth
2 parents ba5bbe1 + d6b22b6 commit fc59ea6

5 files changed

Lines changed: 25 additions & 4 deletions

File tree

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ History
1717
* The version is now retrieved from package metadata at runtime using
1818
``importlib.metadata``. This reduces the chance of version inconsistencies
1919
during releases.
20+
* The async client now builds its ``Authorization`` header with
21+
``aiohttp.encode_basic_auth()`` instead of the ``aiohttp.BasicAuth`` /
22+
``auth=`` parameter, which are deprecated as of aiohttp 3.14.0. As a result,
23+
the minimum required ``aiohttp`` version is now 3.14.0.
2024

2125
3.2.0 (2025-11-20)
2226
++++++++++++++++++

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = [
66
{name = "Gregory Oschwald", email = "goschwald@maxmind.com"},
77
]
88
dependencies = [
9-
"aiohttp>=3.6.2,<4.0.0",
9+
"aiohttp>=3.14.0,<4.0.0",
1010
"email_validator>=2.0.0,<3.0.0",
1111
"geoip2>=5.2.0,<6.0.0",
1212
"requests>=2.24.0,<3.0.0",

src/minfraud/webservice.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,14 @@ async def _do_request(
442442
async def _session(self) -> aiohttp.ClientSession:
443443
if not hasattr(self, "_existing_session"):
444444
self._existing_session = aiohttp.ClientSession(
445-
auth=aiohttp.BasicAuth(self._account_id, self._license_key),
446-
headers={"Accept": "application/json", "User-Agent": _AIOHTTP_UA},
445+
headers={
446+
"Accept": "application/json",
447+
"Authorization": aiohttp.encode_basic_auth(
448+
self._account_id,
449+
self._license_key,
450+
),
451+
"User-Agent": _AIOHTTP_UA,
452+
},
447453
timeout=aiohttp.ClientTimeout(total=self._timeout),
448454
)
449455

tests/test_webservice.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ def test_200(self) -> None:
237237
self.assertEqual("004", model.ip_address.traits.mobile_network_code)
238238
self.assertEqual("ANONYMOUS_IP", model.ip_address.risk_reasons[0].code)
239239

240+
def test_authorization_header(self) -> None:
241+
# Credentials must be sent via the Authorization header rather than the
242+
# deprecated aiohttp BasicAuth / auth= parameter. The expected value is
243+
# base64("42:abcdef123456").
244+
self.create_success()
245+
request, _ = self.httpserver.log[-1]
246+
self.assertEqual(
247+
"Basic NDI6YWJjZGVmMTIzNDU2",
248+
request.headers.get("Authorization"),
249+
)
250+
240251
def test_200_on_request_with_nones(self) -> None:
241252
model = self.create_success(
242253
request={

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)