BHSPitMonkey / homeassistant-garmin-mapshare

Home Assistant custom integration for Garmin MapShare feeds
MIT License
6 stars 1 forks source link

Error fetching garmin mapshare link #2

Closed LW-Ho closed 6 months ago

LW-Ho commented 7 months ago

Hi, I configured my link, but there is an error with the setup.

This is debug message:

2023-12-14 14:37:04.905 ERROR (MainThread) [custom_components.garmin_mapshare.coordinator] Unexpected error fetching garmin_mapshare-mushroomXXXXXXXX data: no element found: line 1, column 0
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1716, in close
    self.parser.Parse(b"", True) # end of data
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
xml.parsers.expat.ExpatError: no element found: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/coordinator.py", line 80, in _async_update_data
    self.raw_values = await self.mapshare.fetch_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/kml_fetch.py", line 37, in fetch_data
    root = ET.fromstring(r.text)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/defusedxml/common.py", line 127, in fromstring
    return parser.close()
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1718, in close
    self._raiseerror(v)
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1618, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: no element found: line 1, column 0
2023-12-14 14:37:04.933 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Garmin MapShare' for garmin_mapshare integration not ready yet: no element found: line 1, column 0; Retrying in background
2023-12-14 14:37:10.290 DEBUG (MainThread) [custom_components.garmin_mapshare.coordinator] MapShareCoordinator: {'link_name': 'mushroomXXXXXXXX '}
2023-12-14 14:37:10.617 DEBUG (MainThread) [custom_components.garmin_mapshare.kml_fetch] Fetched KML data: 
2023-12-14 14:37:10.618 ERROR (MainThread) [custom_components.garmin_mapshare.coordinator] Unexpected error fetching garmin_mapshare-mushroomXXXXXXXX data: no element found: line 1, column 0
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1716, in close
    self.parser.Parse(b"", True) # end of data
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
xml.parsers.expat.ExpatError: no element found: line 1, column 0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/coordinator.py", line 80, in _async_update_data
    self.raw_values = await self.mapshare.fetch_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/kml_fetch.py", line 37, in fetch_data
    root = ET.fromstring(r.text)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/defusedxml/common.py", line 127, in fromstring
    return parser.close()
           ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1718, in close
    self._raiseerror(v)
  File "/usr/local/lib/python3.11/xml/etree/ElementTree.py", line 1618, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: no element found: line 1, column 0
2023-12-14 14:37:10.633 DEBUG (MainThread) [custom_components.garmin_mapshare.coordinator] Finished fetching garmin_mapshare-mushroomXXXXXXXX data in 0.342 seconds (success: False)
2023-12-14 14:37:10.634 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Garmin MapShare' for garmin_mapshare integration not ready yet: no element found: line 1, column 0; Retrying in background
BHSPitMonkey commented 7 months ago

It looks like it's getting an empty response when it tries to download the feed.

You can try downloading the feed yourself by visiting (using your browser, or curl):

# (Replace NAME and PASSPHRASE below)
https://:PASSPHRASE@explore.garmin.com/Feed/Share/NAME

If that succeeds in downloading a KML file, then the name/passphrase should have worked in Home Assistant too. Consider sharing the contents of that file here (after editing out any private info) if it's still not working.

If not, please confirm that you are able to visit https://share.garmin.com/share/NAME in a browser (the normal way) using the same name and passphrase you provided during setup.

LW-Ho commented 7 months ago

Yes, my mapshare without password set, so replacing 'NAME' allows to download feed.kml.

So, I visited this link https://share.garmin.com/share/NAME , and my mapshare appeared as expected.

Thanks.

feed.kml.zip

BHSPitMonkey commented 7 months ago

The feed seems fine, and is parsed correctly when I load it into the integration code manually. I'm not sure why, but it seems like the fetch came back empty (which Garmin will typically do if the NAME is wrong or does not exist).

I've just pushed a new version (v0.2.4) with slightly better logging which may help with identifying the problem.

LW-Ho commented 7 months ago

Hi,

this is debug messages, thanks your debug.

2023-12-16 21:32:15.910 ERROR (MainThread) [custom_components.garmin_mapshare.coordinator] Unexpected error fetching garmin_mapshare-mushroomXXXXXXXXXXX data: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/coordinator.py", line 80, in _async_update_data
    self.raw_values = await self.mapshare.fetch_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/kml_fetch.py", line 38, in fetch_data
    raise ValueError(
ValueError: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
2023-12-16 21:32:15.927 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Garmin MapShare' for garmin_mapshare integration not ready yet: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False; Retrying in background
2023-12-16 21:32:21.315 ERROR (MainThread) [custom_components.garmin_mapshare.coordinator] Unexpected error fetching garmin_mapshare-mushroomXXXXXXXXXXX data: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/coordinator.py", line 80, in _async_update_data
    self.raw_values = await self.mapshare.fetch_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/kml_fetch.py", line 38, in fetch_data
    raise ValueError(
ValueError: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
2023-12-16 21:32:30.724 DEBUG (MainThread) [custom_components.garmin_mapshare.coordinator] MapShareCoordinator: {'link_name': 'mushroomXXXXXXXXXXX'}
2023-12-16 21:32:31.057 ERROR (MainThread) [custom_components.garmin_mapshare.coordinator] Unexpected error fetching garmin_mapshare-mushroomXXXXXXXXXXX data: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/coordinator.py", line 80, in _async_update_data
    self.raw_values = await self.mapshare.fetch_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/kml_fetch.py", line 38, in fetch_data
    raise ValueError(
ValueError: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
2023-12-16 21:32:31.069 DEBUG (MainThread) [custom_components.garmin_mapshare.coordinator] Finished fetching garmin_mapshare-mushroomXXXXXXXXXXX data in 0.343 seconds (success: False)
2023-12-16 21:32:31.070 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Garmin MapShare' for garmin_mapshare integration not ready yet: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False; Retrying in background
2023-12-16 21:32:35.728 DEBUG (MainThread) [custom_components.garmin_mapshare.coordinator] MapShareCoordinator: {'link_name': 'mushroomXXXXXXXXXXX'}
2023-12-16 21:32:36.002 ERROR (MainThread) [custom_components.garmin_mapshare.coordinator] Unexpected error fetching garmin_mapshare-mushroomXXXXXXXXXXX data: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 290, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/coordinator.py", line 80, in _async_update_data
    self.raw_values = await self.mapshare.fetch_data()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/garmin_mapshare/kml_fetch.py", line 38, in fetch_data
    raise ValueError(
ValueError: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False
2023-12-16 21:32:36.013 DEBUG (MainThread) [custom_components.garmin_mapshare.coordinator] Finished fetching garmin_mapshare-mushroomXXXXXXXXXXX data in 0.284 seconds (success: False)
2023-12-16 21:32:36.014 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Garmin MapShare' for garmin_mapshare integration not ready yet: Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX using auth: False; Retrying in background
BHSPitMonkey commented 7 months ago

Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX

Does the logged URL here exactly match the URL you used earlier to download the KML feed?

doggkruse commented 7 months ago

I got bit by using my full URL where it really just wants the NAME component of the url in the setup

LW-Ho commented 7 months ago

Received empty response from https://explore.garmin.com/Feed/Share/mushroomXXXXXXXXXXX

Does the logged URL here exactly match the URL you used earlier to download the KML feed?

Yes, I can use this to download feed.kml

BHSPitMonkey commented 7 months ago

In that case I'm out of ideas for now 😕 Perhaps it's a temporary issue with Garmin's server and the updates will catch up eventually, or if you're using an outbound http proxy behind Home Assistant maybe there could be an issue there. The same request should have the same response in both cases.

LW-Ho commented 7 months ago

In that case I'm out of ideas for now 😕 Perhaps it's a temporary issue with Garmin's server and the updates will catch up eventually, or if you're using an outbound http proxy behind Home Assistant maybe there could be an issue there. The same request should have the same response in both cases.

Thank you for your response. I also use Sonoff and August components in Home Assistant and haven't encountered any network issues.

Thanks to the author!

BHSPitMonkey commented 6 months ago

I wonder if the issue might be a redirect? I noticed that in some other regions, the direct feed URL points to different regional hostnames -- maybe this could explain the difference between the results before.

Can you run the following using your map's NAME (and be sure to redact the NAME in the output if you don't want it visible here):

curl -sv https://explore.garmin.com/Feed/Share/NAME 2>&1 | grep -i location
BHSPitMonkey commented 6 months ago

If that turns out to be the issue, I have a change in main that may fix it. You can try it out by going to HACS -> Integrations -> Garmin MapShare -> menu (top-right corner) -> Redownload and select the version main.

BHSPitMonkey commented 6 months ago

Version v1.0.1 includes that change as well as better logging / error handling messages; Hopefully these can help track down the problem.

BHSPitMonkey commented 6 months ago

@LW-Ho - I've just tagged version v1.1.0 with a new base URL, which I believe may fix this issue for non-USA accounts. Please update using HACS and let me know if that works!

LW-Ho commented 6 months ago

@LW-Ho - I've just tagged version v1.1.0 with a new base URL, which I believe may fix this issue for non-USA accounts. Please update using HACS and let me know if that works!

Thank you very much! This version successfully connects now! Forgot to mention, my account is under the name Taiwan. Also, grateful to the author for identifying this issue.