ol-iver / denonavr

Automation Library for Denon AVR receivers.
MIT License
176 stars 67 forks source link

NetworkError: Server disconnected while attempting read for Denon X1600H #215

Closed dev-zero closed 3 years ago

dev-zero commented 3 years ago

This is what I try in ipython:

In [2]: import denonavr

In [3]: d = denonavr.DenonAVR("192.168.179.35")

In [4]: d.update()
---------------------------------------------------------------------------
ReadError                                 Traceback (most recent call last)
~/.local/lib/python3.9/site-packages/httpx/_transports/default.py in map_httpcore_exceptions()
     60     try:
---> 61         yield
     62     except Exception as exc:

~/.local/lib/python3.9/site-packages/httpx/_transports/default.py in __aiter__(self)
    200         with map_httpcore_exceptions():
--> 201             async for part in self._httpcore_stream:
    202                 yield part

~/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py in __aiter__(self)
     56     async def __aiter__(self) -> AsyncIterator[bytes]:
---> 57         async for chunk in self.stream:
     58             yield chunk

~/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py in __aiter__(self)
     90     async def __aiter__(self) -> AsyncIterator[bytes]:
---> 91         async for chunk in self._aiterator:
     92             yield chunk

~/.local/lib/python3.9/site-packages/httpcore/_async/http11.py in _receive_response_data(self, timeout)
    207         while True:
--> 208             event = await self._receive_event(timeout)
    209             if isinstance(event, h11.Data):

~/.local/lib/python3.9/site-packages/httpcore/_async/http11.py in _receive_event(self, timeout)
    224             if event is h11.NEED_DATA:
--> 225                 data = await self.socket.read(self.READ_NUM_BYTES, timeout)
    226 

~/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py in read(self, n, timeout)
     64             except EndOfStream:
---> 65                 raise ReadError("Server disconnected while attempting read") from None
     66 

ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

ReadError                                 Traceback (most recent call last)
~/.local/lib/python3.9/site-packages/denonavr/decorators.py in wrapper(*args, **kwargs)
     43         try:
---> 44             return await func(*args, **kwargs)
     45         except httpx.HTTPStatusError as err:

~/.local/lib/python3.9/site-packages/denonavr/api.py in async_get(self, request, port)
     84         try:
---> 85             res = await client.get(endpoint, timeout=self.timeout)
     86             res.raise_for_status()

~/.local/lib/python3.9/site-packages/httpx/_client.py in get(self, url, params, headers, cookies, auth, allow_redirects, timeout)
   1660         """
-> 1661         return await self.request(
   1662             "GET",

~/.local/lib/python3.9/site-packages/httpx/_client.py in request(self, method, url, content, data, files, json, params, headers, cookies, auth, allow_redirects, timeout)
   1424         )
-> 1425         response = await self.send(
   1426             request, auth=auth, allow_redirects=allow_redirects, timeout=timeout

~/.local/lib/python3.9/site-packages/httpx/_client.py in send(self, request, stream, auth, allow_redirects, timeout)
   1527             await response.aclose()
-> 1528             raise exc
   1529 

~/.local/lib/python3.9/site-packages/httpx/_client.py in send(self, request, stream, auth, allow_redirects, timeout)
   1518             if not stream:
-> 1519                 await response.aread()
   1520 

~/.local/lib/python3.9/site-packages/httpx/_models.py in aread(self)
   1560         if not hasattr(self, "_content"):
-> 1561             self._content = b"".join([part async for part in self.aiter_bytes()])
   1562         return self._content

~/.local/lib/python3.9/site-packages/httpx/_models.py in <listcomp>(.0)
   1560         if not hasattr(self, "_content"):
-> 1561             self._content = b"".join([part async for part in self.aiter_bytes()])
   1562         return self._content

~/.local/lib/python3.9/site-packages/httpx/_models.py in aiter_bytes(self, chunk_size)
   1576             with request_context(request=self._request):
-> 1577                 async for raw_bytes in self.aiter_raw():
   1578                     decoded = decoder.decode(raw_bytes)

~/.local/lib/python3.9/site-packages/httpx/_models.py in aiter_raw(self, chunk_size)
   1630         with request_context(request=self._request):
-> 1631             async for raw_stream_bytes in self.stream:
   1632                 self._num_bytes_downloaded += len(raw_stream_bytes)

~/.local/lib/python3.9/site-packages/httpx/_client.py in __aiter__(self)
    126     async def __aiter__(self) -> typing.AsyncIterator[bytes]:
--> 127         async for chunk in self._stream:
    128             yield chunk

~/.local/lib/python3.9/site-packages/httpx/_transports/default.py in __aiter__(self)
    201             async for part in self._httpcore_stream:
--> 202                 yield part
    203 

/usr/lib/python3.9/contextlib.py in __exit__(self, type, value, traceback)
    134             try:
--> 135                 self.gen.throw(type, value, traceback)
    136             except StopIteration as exc:

~/.local/lib/python3.9/site-packages/httpx/_transports/default.py in map_httpcore_exceptions()
     77         message = str(exc)
---> 78         raise mapped_exc(message) from exc
     79 

ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

AvrNetworkError                           Traceback (most recent call last)
<ipython-input-4-22f220a7b35f> in <module>
----> 1 d.update()

~/.local/lib/python3.9/site-packages/denonavr/decorators.py in wrapper(*args, **kwargs)
    144 
    145             try:
--> 146                 return loop.run_until_complete(async_func(*args, **kwargs))
    147             finally:
    148                 loop.close()

/usr/lib/python3.9/asyncio/base_events.py in run_until_complete(self, future)
    640             raise RuntimeError('Event loop stopped before Future completed.')
    641 
--> 642         return future.result()
    643 
    644     def stop(self):

~/.local/lib/python3.9/site-packages/denonavr/denonavr.py in async_update(self)
    155         # Ensure that the device is setup
    156         if self._is_setup is False:
--> 157             await self.async_setup()
    158 
    159         # Create a cache id for this global update

~/.local/lib/python3.9/site-packages/denonavr/denonavr.py in async_setup(self)
    130         """Ensure that configuration is loaded from receiver asynchronously."""
    131         # Device setup
--> 132         await self._device.async_setup()
    133         if self._name is None:
    134             self._name = self._device.friendly_name

~/.local/lib/python3.9/site-packages/denonavr/foundation.py in async_setup(self)
     95         """Ensure that configuration is loaded from receiver asynchronously."""
     96         # Own setup
---> 97         await self.async_identify_receiver()
     98         await self.async_identify_update_method()
     99         await self.async_get_device_info()

~/.local/lib/python3.9/site-packages/denonavr/foundation.py in async_identify_receiver(self)
    130             try:
    131                 # Deviceinfo.xml is static and can be cached for the whole time
--> 132                 xml = await self.api.async_get_xml(
    133                     self.urls.deviceinfo, cache_id=id(self))
    134             except (AvrTimoutError, AvrNetworkError) as err:

~/.local/lib/python3.9/site-packages/denonavr/decorators.py in wrapper(*args, **kwargs)
     94     async def wrapper(*args, **kwargs):
     95         try:
---> 96             return await func(*args, **kwargs)
     97         except Exception as err:
     98             _LOGGER.debug("Exception %s raised, clearing cache", err)

~/.local/lib/python3.9/site-packages/asyncstdlib/_lrucache.py in wrapper(*args, **kwargs)
    286         except KeyError:
    287             misses += 1
--> 288             result = await function(*args, **kwargs)
    289             # function finished early for another call with the same arguments
    290             # the cache has been updated already, do nothing to it

~/.local/lib/python3.9/site-packages/denonavr/decorators.py in wrapper(*args, **kwargs)
     42     async def wrapper(*args, **kwargs):
     43         try:
---> 44             return await func(*args, **kwargs)
     45         except httpx.HTTPStatusError as err:
     46             _LOGGER.debug(

~/.local/lib/python3.9/site-packages/denonavr/api.py in async_get_xml(self, request, cache_id)
    137         """Return XML data from HTTP GET endpoint asynchronously."""
    138         # HTTP GET to endpoint
--> 139         res = await self.async_get(request)
    140         # create ElementTree
    141         xml_root = fromstring(res.text)

~/.local/lib/python3.9/site-packages/denonavr/decorators.py in wrapper(*args, **kwargs)
     62                 "Network error exception on request %s", err.request,
     63                 exc_info=True)
---> 64             raise AvrNetworkError(
     65                 "NetworkError: {}".format(err), err.request) from err
     66         except httpx.RemoteProtocolError as err:

AvrNetworkError: NetworkError: Server disconnected while attempting read

while curl gives me:

$ curl -vkL 192.168.179.35
*   Trying 192.168.179.35:80...
* Connected to 192.168.179.35 (192.168.179.35) port 80 (#0)
> GET / HTTP/1.1
> Host: 192.168.179.35
> User-Agent: curl/7.77.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 301 Moved Permanently
< Location: https://192.168.179.35:10443
* Connection #0 to host 192.168.179.35 left intact
* Issue another request to this URL: 'https://192.168.179.35:10443/'
*   Trying 192.168.179.35:10443...
* Connected to 192.168.179.35 (192.168.179.35) port 10443 (#1)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*  CAfile: /etc/ssl/certs/ca-certificates.crt
*  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=JP; ST=Kanagawa; L=Kawasaki-shi; O=Sound United, LLC; CN=Sound United
*  start date: Mar 12 04:46:34 2019 GMT
*  expire date: Feb 27 04:46:34 2069 GMT
*  issuer: C=JP; ST=Kanagawa; L=Kawasaki-shi; O=Sound United, LLC; CN=Sound United
*  SSL certificate verify result: self signed certificate (18), continuing anyway.
> GET / HTTP/1.1
> Host: 192.168.179.35:10443
> User-Agent: curl/7.77.0
> Accept: */*
> 
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: Boost.Beast/277
< Content-Type: text/html
< Content-Length: 1688
< 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">

    <head>
        <meta http-equiv="Pragma" content="no-cache">
        <meta http-equiv="Cache-Control" content="no-cache">
        <title>Home</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
        <link rel="stylesheet" type="text/css" href="common.css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="polyfill.min.js"></script>
        <script type="text/javascript" src="GlobalsServerInterface.js"></script>
        <script type="text/javascript" src="HomeServerInterface.js"></script>
        <script type="text/javascript" src="GlobalsSettings.js"></script>
        <script type="text/javascript" src="HomeSettings.js"></script>
        <script type="text/javascript" src="LanguageStrings.js"></script>
    </head>

    <body>
        <div class="main">
            <div class="left">
                <div class="iconleftmenu">
                    <div id="menutitle" class="config-title"></div>
                    <div class="iconleftmenutitle"></div>
                    <ul></ul>
                </div>            
            </div>
            <div class="right">
                <div class="rightheader">
                    <div id="friendlyname" class="config-title"></div>
                    <ul></ul>
                </div>
            </div>
        </div>
    </body>

</html>
* Connection #1 to host 192.168.179.35 left intact
dev-zero commented 3 years ago

with a simple script and more logging I get:

$ python conn.py 
DEBUG:asyncio:Using selector: EpollSelector
DEBUG:httpx._client:HTTP Request: GET http://192.168.179.35/goform/Deviceinfo.xml "HTTP/1.1 403 Forbidden"
DEBUG:denonavr.decorators:Network error exception on request <Request('GET', 'http://192.168.179.35/goform/Deviceinfo.xml')>
Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 201, in __aiter__
    async for part in self._httpcore_stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 57, in __aiter__
    async for chunk in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py", line 91, in __aiter__
    async for chunk in self._aiterator:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 208, in _receive_response_data
    event = await self._receive_event(timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 65, in read
    raise ReadError("Server disconnected while attempting read") from None
httpcore.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 85, in async_get
    res = await client.get(endpoint, timeout=self.timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1661, in get
    return await self.request(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1425, in request
    response = await self.send(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1528, in send
    raise exc
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1519, in send
    await response.aread()
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in aread
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in <listcomp>
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1577, in aiter_bytes
    async for raw_bytes in self.aiter_raw():
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1631, in aiter_raw
    async for raw_stream_bytes in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 127, in __aiter__
    async for chunk in self._stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 202, in __aiter__
    yield part
  File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError: Server disconnected while attempting read
DEBUG:denonavr.decorators:Exception NetworkError: Server disconnected while attempting read raised, clearing cache
DEBUG:denonavr.foundation:Connection error on port 80 when identifying receiver
Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 201, in __aiter__
    async for part in self._httpcore_stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 57, in __aiter__
    async for chunk in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py", line 91, in __aiter__
    async for chunk in self._aiterator:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 208, in _receive_response_data
    event = await self._receive_event(timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 65, in read
    raise ReadError("Server disconnected while attempting read") from None
httpcore.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 85, in async_get
    res = await client.get(endpoint, timeout=self.timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1661, in get
    return await self.request(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1425, in request
    response = await self.send(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1528, in send
    raise exc
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1519, in send
    await response.aread()
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in aread
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in <listcomp>
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1577, in aiter_bytes
    async for raw_bytes in self.aiter_raw():
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1631, in aiter_raw
    async for raw_stream_bytes in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 127, in __aiter__
    async for chunk in self._stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 202, in __aiter__
    yield part
  File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/foundation.py", line 132, in async_identify_receiver
    xml = await self.api.async_get_xml(
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 96, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/asyncstdlib/_lrucache.py", line 288, in wrapper
    result = await function(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 139, in async_get_xml
    res = await self.async_get(request)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 64, in wrapper
    raise AvrNetworkError(
denonavr.exceptions.AvrNetworkError: NetworkError: Server disconnected while attempting read
DEBUG:httpx._client:HTTP Request: GET http://192.168.179.35:8080/goform/Deviceinfo.xml "HTTP/1.0 200 OK"
DEBUG:denonavr.decorators:Network error exception on request <Request('GET', 'http://192.168.179.35:8080/goform/Deviceinfo.xml')>
Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 201, in __aiter__
    async for part in self._httpcore_stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 57, in __aiter__
    async for chunk in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py", line 91, in __aiter__
    async for chunk in self._aiterator:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 208, in _receive_response_data
    event = await self._receive_event(timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 65, in read
    raise ReadError("Server disconnected while attempting read") from None
httpcore.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 85, in async_get
    res = await client.get(endpoint, timeout=self.timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1661, in get
    return await self.request(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1425, in request
    response = await self.send(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1528, in send
    raise exc
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1519, in send
    await response.aread()
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in aread
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in <listcomp>
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1577, in aiter_bytes
    async for raw_bytes in self.aiter_raw():
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1631, in aiter_raw
    async for raw_stream_bytes in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 127, in __aiter__
    async for chunk in self._stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 202, in __aiter__
    yield part
  File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError: Server disconnected while attempting read
DEBUG:denonavr.decorators:Exception NetworkError: Server disconnected while attempting read raised, clearing cache
DEBUG:denonavr.foundation:Connection error on port 8080 when identifying receiver
Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 201, in __aiter__
    async for part in self._httpcore_stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 57, in __aiter__
    async for chunk in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py", line 91, in __aiter__
    async for chunk in self._aiterator:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 208, in _receive_response_data
    event = await self._receive_event(timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 65, in read
    raise ReadError("Server disconnected while attempting read") from None
httpcore.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 85, in async_get
    res = await client.get(endpoint, timeout=self.timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1661, in get
    return await self.request(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1425, in request
    response = await self.send(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1528, in send
    raise exc
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1519, in send
    await response.aread()
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in aread
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in <listcomp>
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1577, in aiter_bytes
    async for raw_bytes in self.aiter_raw():
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1631, in aiter_raw
    async for raw_stream_bytes in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 127, in __aiter__
    async for chunk in self._stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 202, in __aiter__
    yield part
  File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/foundation.py", line 132, in async_identify_receiver
    xml = await self.api.async_get_xml(
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 96, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/asyncstdlib/_lrucache.py", line 288, in wrapper
    result = await function(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 139, in async_get_xml
    res = await self.async_get(request)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 64, in wrapper
    raise AvrNetworkError(
denonavr.exceptions.AvrNetworkError: NetworkError: Server disconnected while attempting read
Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 201, in __aiter__
    async for part in self._httpcore_stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 57, in __aiter__
    async for chunk in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py", line 91, in __aiter__
    async for chunk in self._aiterator:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 208, in _receive_response_data
    event = await self._receive_event(timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 65, in read
    raise ReadError("Server disconnected while attempting read") from None
httpcore.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 85, in async_get
    res = await client.get(endpoint, timeout=self.timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1661, in get
    return await self.request(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1425, in request
    response = await self.send(
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1528, in send
    raise exc
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 1519, in send
    await response.aread()
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in aread
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1561, in <listcomp>
    self._content = b"".join([part async for part in self.aiter_bytes()])
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1577, in aiter_bytes
    async for raw_bytes in self.aiter_raw():
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_models.py", line 1631, in aiter_raw
    async for raw_stream_bytes in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_client.py", line 127, in __aiter__
    async for chunk in self._stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 202, in __aiter__
    yield part
  File "/usr/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ReadError: Server disconnected while attempting read

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/tiziano/work/tests/python/denon/conn.py", line 7, in <module>
    d.update()
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 146, in wrapper
    return loop.run_until_complete(async_func(*args, **kwargs))
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/denonavr.py", line 157, in async_update
    await self.async_setup()
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/denonavr.py", line 132, in async_setup
    await self._device.async_setup()
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/foundation.py", line 97, in async_setup
    await self.async_identify_receiver()
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/foundation.py", line 132, in async_identify_receiver
    xml = await self.api.async_get_xml(
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 96, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/asyncstdlib/_lrucache.py", line 288, in wrapper
    result = await function(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 44, in wrapper
    return await func(*args, **kwargs)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/api.py", line 139, in async_get_xml
    res = await self.async_get(request)
  File "/home/tiziano/.local/lib/python3.9/site-packages/denonavr/decorators.py", line 64, in wrapper
    raise AvrNetworkError(
denonavr.exceptions.AvrNetworkError: NetworkError: Server disconnected while attempting read
import logging
import denonavr

logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
d = denonavr.DenonAVR("192.168.179.35")
d.update()

... it seems that port 80 is used instead of 8080:

$ curl http://192.168.179.35:8080/goform/Deviceinfo.xml | head -n 10
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0<?xml version="1.0" encoding="utf-8" ?>
<Device_Info>
<DeviceInfoVers>0001</DeviceInfoVers>
<CommApiVers>0301</CommApiVers>
<Gen>0002</Gen>
<BrandCode>0</BrandCode>
<ProductCategory>01</ProductCategory>
<CategoryName>AV RECEIVER</CategoryName>
<ManualModelName>AVR-X1600H</ManualModelName>
<DeliveryCode>02</DeliveryCode>
dev-zero commented 3 years ago

changing the order to what is documented here (e.g. to [AVR_X_2016, AVR_X]).

https://github.com/scarface-4711/denonavr/blob/63baed4c53d2cfbd1a5dfde7b23aa953aa81d37f/denonavr/foundation.py#L123-L124

still generates an error:

$ python conn.py DEBUG:asyncio:Using selector: EpollSelector
DEBUG:httpx._client:HTTP Request: GET http://192.168.179.35:8080/goform/Deviceinfo.xml "HTTP/1.0 200 OK"
DEBUG:denonavr.decorators:Network error exception on request <Request('GET', 'http://192.168.179.35:8080/goform/Deviceinfo.xml')>
Traceback (most recent call last):
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpx/_transports/default.py", line 201, in __aiter__
    async for part in self._httpcore_stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 57, in __aiter__
    async for chunk in self.stream:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_bytestreams.py", line 91, in __aiter__
    async for chunk in self._aiterator:
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 208, in _receive_response_data
    event = await self._receive_event(timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_async/http11.py", line 225, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/home/tiziano/.local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 65, in read
    raise ReadError("Server disconnected while attempting read") from None
httpcore.ReadError: Server disconnected while attempting read
...
dev-zero commented 3 years ago

It seems to be httpxs fault.

This works:

import httpx
r = httpx.get('http://192.168.179.35:8080/goform/Deviceinfo.xml')
print(r)

this doesn't:

import httpx
import asyncio

async def main():
    async with httpx.AsyncClient() as client:
        r = await client.get('http://192.168.179.35:8080/goform/Deviceinfo.xml')

    print(r)

asyncio.run(main())
dev-zero commented 3 years ago

See also: https://community.home-assistant.io/t/denonavr-not-working-since-2021-6-4/315266/17

dev-zero commented 3 years ago

and opened discussion here: https://github.com/encode/httpx/discussions/1689

dev-zero commented 3 years ago

This is solved with httpcore 0.13.6 (and was broken with httpcore 0.13.4).