PetHubLocal / pethublocal

Replacement for SurePetCare "Connect" cloud service connecting via MQTT to Home Assistant
MIT License
73 stars 9 forks source link

Error downloading firmware #2

Open peedub opened 2 years ago

peedub commented 2 years ago

During setup, I get the following error when trying to download the firmware. Setup completes successfully if I say no to this step.

Download Credentials and Firmware for Hub (highly recommended)? Y/N y
INFO:pethublocal:Current Hub Firmware 2.43
INFO:pethublocal:Downloading Current Firmware for H004-0081844
INFO:pethublocal:SureHub Host hub.api.surehub.io IP Address: 10.1.1.183
INFO:pethublocal:Downloading first firmware record to get header information
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 10.1.1.183:80
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 281, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 550, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.9/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/usr/local/lib/python3.9/http/client.py", line 1377, in getresponse
    response.begin()
  File "/usr/local/lib/python3.9/http/client.py", line 320, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.9/http/client.py", line 281, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/usr/local/lib/python3.9/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/pethublocal", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/pethublocal/cli/__init__.py", line 72, in setup
    pethubconfig = config_load(True, force)
  File "/usr/local/lib/python3.9/site-packages/pethublocal/functions.py", line 378, in config_load
    log.info(download_firmware(serial_number, force))
  File "/usr/local/lib/python3.9/site-packages/pethublocal/functions.py", line 98, in download_firmware
    download_firmware_record(surehubio, serialnumber, BOOTLOADER, 0)
  File "/usr/local/lib/python3.9/site-packages/pethublocal/functions.py", line 76, in download_firmware_record
    response = requests.post(url, data=postdata, headers=headers, verify=False)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 115, in post
    return request("post", url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 547, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))
plambrechtsen commented 2 years ago

Try removing the DNS Poisoning as it seems to only be querying the local host... humm let be check the code but it is hitting the local server rather than going out to the internet.

INFO:pethublocal:SureHub Host hub.api.surehub.io IP Address: 10.1.1.183
INFO:pethublocal:Downloading first firmware record to get header information
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 10.1.1.183:80
plambrechtsen commented 2 years ago

Or another issue could be you are posioning the Google DNS IP, you may need to update https://github.com/PetHubLocal/pethublocal/blob/main/pethublocal/consts.py#L22 to point to your ISP DNS server.

peedub commented 2 years ago

Thanks again. I have a dns server here and all port 53 traffic is forced through it so that is likely it. I'll update you once I change that.

plambrechtsen commented 2 years ago

I assume you've sorted this in the end and your internal DNS poisoning was the issue?

jacotec commented 2 years ago

I can confirm this, I also redirect all DNS queries to my local DNS resolver and had the same error. Once I've configured an exception for my HomeAssistant Server in my pfSense, the firmware download works!

So it's a kind of an "external" error and that might be closed. (However, why does it need the Google servers?)

plambrechtsen commented 2 years ago

I will add further information into the docs about this. As the DNS poisoning is essential to the hub operation, but only after downloading the firmware. Using Google DNS seemed at the time the easiest option to differentiate between the internal DNS and public, but perhaps I should make it clear during setup and do a query to the default DNS and Google DNS and if I get the same response and they are a RFC1918 address then something is wrong and to log an issue. As the cloud IP should always be an AWS IP (unless Surepet move off AWS.. which is very unlikely(?)) Food for thought so will leave this as an issue.

jacotec commented 2 years ago

Ah, understand ... the FW download needs "real" access to hub.api... which is poisoned on the local DNS. Clear now ;-)