Skip to content

Commit b1ff073

Browse files
committed
more compat fixes
1 parent 12a9c52 commit b1ff073

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

onvif/client.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ def __init__(
248248
self.dt_diff = dt_diff
249249
self.binding_name = binding_name
250250
# Create soap client
251-
connector = TCPConnector(
251+
self._connector = TCPConnector(
252252
ssl=_NO_VERIFY_SSL_CONTEXT,
253253
keepalive_timeout=KEEPALIVE_EXPIRY,
254254
)
255-
session = ClientSession(
256-
connector=connector,
255+
self._session = ClientSession(
256+
connector=self._connector,
257257
timeout=aiohttp.ClientTimeout(
258258
total=_DEFAULT_TIMEOUT,
259259
connect=_CONNECT_TIMEOUT,
@@ -262,12 +262,12 @@ def __init__(
262262
)
263263
self.transport = (
264264
AsyncTransportProtocolErrorHandler(
265-
session=session,
265+
session=self._session,
266266
verify_ssl=False,
267267
)
268268
if no_cache
269269
else AIOHTTPTransport(
270-
session=session,
270+
session=self._session,
271271
verify_ssl=False,
272272
cache=SqliteCache(),
273273
)
@@ -316,6 +316,8 @@ async def setup(self):
316316
async def close(self):
317317
"""Close the transport."""
318318
await self.transport.aclose()
319+
await self._session.close()
320+
await self._connector.close()
319321

320322
@staticmethod
321323
@safe_func

onvif/managers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(
6262
@property
6363
def closed(self) -> bool:
6464
"""Return True if the manager is closed."""
65-
return not self._subscription or self._subscription.transport.client.is_closed
65+
return not self._subscription or self._subscription.transport.session.closed
6666

6767
async def start(self) -> None:
6868
"""Setup the manager."""

onvif/zeep_aiohttp.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,17 +159,18 @@ async def _post(
159159
proxy=self.proxy,
160160
timeout=self._client_timeout,
161161
)
162-
response.raise_for_status()
163162

164-
# Read the content to log it
163+
# Read the content to log it before checking status
165164
content = await response.read()
166165
_LOGGER.debug(
167166
"HTTP Response from %s (status: %d):\n%s",
168167
address,
169168
response.status,
170-
content.decode("utf-8", errors="replace"),
169+
content,
171170
)
172171

172+
response.raise_for_status()
173+
173174
# Convert to httpx Response
174175
return self._aiohttp_to_httpx_response(response, content)
175176

@@ -236,17 +237,19 @@ async def _get(
236237
proxy=self.proxy,
237238
timeout=self._client_timeout,
238239
)
239-
response.raise_for_status()
240240

241-
# Read content
241+
# Read content and log before checking status
242242
content = await response.read()
243243

244244
_LOGGER.debug(
245-
"HTTP Response from %s (status: %d)",
245+
"HTTP Response from %s (status: %d):\n%s",
246246
address,
247247
response.status,
248+
content,
248249
)
249250

251+
response.raise_for_status()
252+
250253
# Convert directly to requests.Response
251254
return self._aiohttp_to_requests_response(response, content)
252255

0 commit comments

Comments
 (0)