Skip to content

Commit e67106e

Browse files
authored
Merge pull request #890 from plugwise/basic_auth
Solve aiohttp BascicAuth depreciation
2 parents af974b3 + 123fbc3 commit e67106e

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
## Ongoing
44

5-
- Add PEP 740 digital attestations (workaround until included in `uv publish`)
6-
- Pin GitHub acions including our own from gh-actions
5+
- Add PEP 740 digital attestations (workaround until included in `uv publish`), pin GitHub acions including our own from gh-actions, via PR [#891](https://github.com/plugwise/python-plugwise/pull/891)
6+
- Solve aiohttp BasicAuth deprecation via PR [#890](https://github.com/plugwise/python-plugwise/pull/890)
77

88
## v1.12.0
99

plugwise/smilecomm.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
from plugwise.util import escape_illegal_xml_characters
1616

1717
# This way of importing aiohttp is because of patch/mocking in testing (aiohttp timeouts)
18-
from aiohttp import BasicAuth, ClientError, ClientResponse, ClientSession, ClientTimeout
18+
from aiohttp import (
19+
ClientError,
20+
ClientResponse,
21+
ClientSession,
22+
ClientTimeout,
23+
encode_basic_auth,
24+
)
1925
from defusedxml import ElementTree as etree
2026

2127

@@ -42,7 +48,9 @@ def __init__(
4248
if host.count(":") > 2: # pragma: no cover
4349
host = f"[{host}]"
4450

45-
self._auth = BasicAuth(username, password=password)
51+
self._base_header = {
52+
"Authorization": encode_basic_auth(username, password=password)
53+
}
4654
self._endpoint = f"http://{host}:{str(port)}" # Sensitive
4755

4856
async def _request(
@@ -58,28 +66,24 @@ async def _request(
5866
try:
5967
match method:
6068
case "delete":
61-
resp = await self._websession.delete(url, auth=self._auth)
69+
resp = await self._websession.delete(url, headers=self._base_header)
6270
case "get":
6371
# Work-around for Stretchv2, should not hurt the other smiles
64-
headers = {"Accept-Encoding": "gzip"}
65-
resp = await self._websession.get(
66-
url, headers=headers, auth=self._auth
67-
)
72+
headers = {**self._base_header, "Accept-Encoding": "gzip"}
73+
resp = await self._websession.get(url, headers=headers)
6874
case "post":
69-
headers = {"Content-type": "text/xml"}
75+
headers = {**self._base_header, "Content-type": "text/xml"}
7076
resp = await self._websession.post(
7177
url,
7278
headers=headers,
7379
data=data,
74-
auth=self._auth,
7580
)
7681
case "put":
77-
headers = {"Content-type": "text/xml"}
82+
headers = {**self._base_header, "Content-type": "text/xml"}
7883
resp = await self._websession.put(
7984
url,
8085
headers=headers,
8186
data=data,
82-
auth=self._auth,
8387
)
8488
except (
8589
ClientError

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ maintainers = [
2727
requires-python = ">=3.13"
2828
dependencies = [
2929
"aiofiles",
30-
"aiohttp",
30+
"aiohttp>=3.14",
3131
"defusedxml",
3232
"munch",
3333
"python-dateutil",

0 commit comments

Comments
 (0)