Core: google_maps not initializing, throwing lib errors

Created on 14 Apr 2018  路  30Comments  路  Source: home-assistant/core

Home Assistant release with the issue:
0.67.0

Last working Home Assistant release (if known):
none

Operating environment (Hass.io/Docker/Windows/etc.):
VirtEnv Raspbian@RasPi3b+ | Python 3.5.3

Component/platform:
device_tracker.google_maps

Description of problem:
platform does not seem to initialize, though I have received authentication warning (which I approved) for the account.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

device_tracker:
  ...
  - platform: google_maps
    username: [email protected]
    password: xxxxxxxx

Traceback (if applicable):
first:

Apr 14 20:06:45 MrMeeSeeks hass[7343]: ERROR:locationsharinglib.Service:Could not open pickle file, either file does not exist or no read access.

and then recurring:

2018-04-14 21:18:05 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform google_maps
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 184, in async_setup_platform
    disc_info)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/google_maps.py", line 36, in setup_scanner
    scanner = GoogleMapsScanner(hass, config, see)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/google_maps.py", line 55, in __init__
    self._update_info()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/google_maps.py", line 67, in _update_info
    for person in self.service.get_all_people():
  File "/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 292, in get_all_people
    return self._get_data()
  File "/srv/homeassistant/lib/python3.5/site-packages/cachetools/__init__.py", line 46, in wrapper
    v = func(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 283, in _get_data
    output = json.loads(response.text.split("'", 1)[1])
  File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

[edited to focus on the persisting issue]

Most helpful comment

This is the error I'm getting:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 284, in _get_data
    people = [Person(info) for info in output[0]]
TypeError: 'NoneType' object is not iterable

I created a new account, shared the location, said that it was me logging in on the device activity screen, and I tried toggling on "Allow less secure apps." Nothing seems to work.

All 30 comments

@michaelarnauts any ideas?

I ran into the same issue. It seems it's trying to iterate over an empty list. I added my primary account to my homeassistant gmail account and am able to now see my device location in Home Assistant.

So you have to use additional account (can be new) with which you will share your location on the phone. Then you use the additional's accounts credentials in this component in HA.

basically, you need to use credential of any account showing in https://myaccount.google.com/locationsharing

I didn't read it right the first time either.

Anyway, when I set it up like that, I'm still not able to get it to work, I'm not receiveing the logon warning and dont see the logon from HA on the https://myaccount.google.com/device-activity page of the additional account.

Apr 14 17:29:37 MrMeeSeeks hass[2955]: ERROR:homeassistant.components.device_tracker:Error setting up platform google_maps
Apr 14 17:29:37 MrMeeSeeks hass[2955]: Traceback (most recent call last):
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/__init__.py", line 184, in async_setup_platform
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     disc_info)
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     yield self  # This tells Task to wait for completion.
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     future.result()
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     raise self._exception
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     result = self.fn(*self.args, **self.kwargs)
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/google_maps.py", line 36, in setup_scanner
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     scanner = GoogleMapsScanner(hass, config, see)
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/google_maps.py", line 55, in __init__
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     self._update_info()
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/device_tracker/google_maps.py", line 67, in _update_info
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     for person in self.service.get_all_people():
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 292, in get_all_people
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     return self._get_data()
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/cachetools/__init__.py", line 46, in wrapper
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     v = func(*args, **kwargs)
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 283, in _get_data
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     output = json.loads(response.text.split("'", 1)[1])
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     return _default_decoder.decode(s)
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Apr 14 17:29:37 MrMeeSeeks hass[2955]:   File "/usr/lib/python3.5/json/decoder.py", line 357, in raw_decode
Apr 14 17:29:37 MrMeeSeeks hass[2955]:     raise JSONDecodeError("Expecting value", s, err.value) from None
Apr 14 17:29:37 MrMeeSeeks hass[2955]: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

[edit] I have also deleted cookies file, it does get re-created but does not change the situation.

@ferdydek , just to repeat and clarify what I believe is being described, you basically need to create a slave account which you send your device location(s) to via Location Sharing. You would then supply the credentials of this slave account to HASS and use it to log in. I'll test this and report back

Out of curiosity do you use 2FA or some other login challenge? I was troubleshooting this same symptom on my end. I have 2-Factor Authentication enabled on all of my google accounts and presumed I could supply an App Password for one of my slave accounts as I have done in the past for apps which can't pass 2-factor challenges. However, that doesn't work here.

It appears generated App Passwords can be used for rudimentary functions such as SMTP/IMAP authentication but seem to be prohibited from use in HTTP/API authentication, though I can't find any documentation anywhere citing what these can or cannot

I also noticed that while I was able to supply my main google account's user/password once from a blank-slate by approving a phone login prompt when challenged, restarting my HASS docker container left a stale cookie behind in the config path that must be removed in order to re-authenticate.

...and that worked!

  • I created a brand new gmail account intended to service homeassistant exclusively ([email protected]) with a complex passphrase and no 2FA, nor any other login challenges
  • Shared my device's location with [email protected]
  • Removed the stale .google_maps_location_sharing.cookies file from the config path
  • Signed in once using chrome, was neither challenged nor forced to approve any sign-ins
  • Fed credentials into my HASS config, restarted and immediately saw my user with a valid location. No challenge or approval was required.

While I've read some comments suggesting multi-user isn't working correctly, I have successfully tested both a single entity account (myself) and multiple entities (myself and wife). Both work great.

No F2A, no special environment. Did what you did and I'm still getting the error ERROR:homeassistant.components.device_tracker:Error setting up platform google_maps.

@Sanfam I was attempting to use an existing account which did have 2FA enabled. I created a new one specifically for HA as you did, followed your other steps, and now it's up.

so or its something with my tracked account (it actually has special characters, maybe thats an issue) or has to do with my Py/pip versions.
How is the entity named for you guys? device_tracker.<google_nickname> ?

@ferdydek , I see device_tracker.google maps ##################### for both the wife and I, where the #'s represent a string of digits that length. I see three fields it could possibly barf on if it wasn't being processed correctly: nickname, full_name, and address. While the tracker name doesn't have special characters I wonder if one of those breaks it?

@cogneato glad I could help!

Could not open pickle file, either file does not exist or no read access.

I have different error.

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 284, in _get_data
    people = [Person(info) for info in output[0]]
  File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 284, in <listcomp>
    people = [Person(info) for info in output[0]]
  File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 87, in __init__
    self._populate(data)
  File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 95, in _populate
    self._latitude = data[1][1][2]
TypeError: 'NoneType' object is not subscriptable

This is the error I'm getting:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 284, in _get_data
    people = [Person(info) for info in output[0]]
TypeError: 'NoneType' object is not iterable

I created a new account, shared the location, said that it was me logging in on the device activity screen, and I tried toggling on "Allow less secure apps." Nothing seems to work.

I can confirm what @Sanfam said worked for me. I was having "Could not open pickle file, either file does not exist or no read access.".

I stopped home assistant, deleted a previously created ".cookies" and ".conf" file from the home assistant directory, and then started home assistant back up and it worked fine.

I can also confirm that I solved the problem by removing the .cookies file and restarted.

My guess is that the .cookies file should be recreated when the configuration change.

Hi,
I configured another gmail account on my HassIo conf file then,
I tried 3 or 4 times to solve my issue by removing the .cookies file but nothing change.
I received emails to warn me that there is a suspicious connexion but everytime I had to say: "ok it's safe" without the possibility to "lock" my answer and the device/IP.
Don't know what to do now but I won't give up! :)

@Klathmon what .conf file are you referring to? I only see the cookie file.

I was running a pre-release version of this script, so it may have been created then, or I may be misremembering...

Having the same issue. Worked the first time I configured it, then stopped working after Hass restart, I get same errors in log as described in OPs comment.

Tried the following:

  • remove/readd credentials in config
  • remove cookie file and restart
  • allow less secure apps

From time to time, I get a prompt forcing to the confirm "I'm not a robot" when visiting Google sites.

i'm also getting the "i'm not a robot" messages. Became so frequent i actually disabled the component.

Do you know if we have to authorize, add or do something else into the Google API Console ? If yes, with the secondary account? Which Google Maps API is used on HassIO? The Android version, Javascript version...?
Really not sure that it's a solution but I try, I try :)

Ok! Forget those API things! It's working now! How:
I opened the device where I've installed Google Maps and, in the settings, share my position to my main Google account.
Without Google Maps launched, the device told me to accept to share my position ( as it already did the first time ) and then I came back to HassIO and it's working!
I see that my known_devices.yaml has changed and I've got a "google_maps_xxxxxxxxxxxxxxxxxx" line!
I just need to add this to a group! Great!

PS: It seems that it has worked without delete the cookie file and restart HassIO. It was one hour after my 73rd attempted to delete and restart ^^
PS' : Sorry for my english ^^ Hope it will help you
Note: In fact I see that it's my main account who is tracked on HassIO...Maybe because I add it on Google Maps on the same device...weird....

Good tip @Edmond76, I was not seeing the device in HA as device_tracker because it was not configured in known_devices.conf with track: true. Duh! :D

So to recap:

  • you have to use separate "service" account with which in google maps of your target account you share your location,
  • on any change of credentials in the .yaml configuration you have to delete the cookie file manually (@michaelarnauts can this be fixed?),
  • once you see fresh cookies file head to known_devices.yaml and set track: to true. (@michaelarnauts can this be fixed as well?)

Should we not just remove the use of cookie (it's seems to be flaky). when i test the lib just with username and password it seems to work corectly.

can we change this :

self.service = Service(self.username, self.password,
hass.config.path(CREDENTIALS_FILE))

to this :

self.service = Service(self.username, self.password)

and add more exception ? :

except InvalidUser:
            _LOGGER.error('You have specified invalid login credentials')
self.success_init = False

My understanding was that the cookie prevents excessive "prove you're not a robot" and fake logon events, but im not sure if that is the case.

but if you check your device as trusted in google security manager console it will avoid to consider you as a robot right ?

i try 5 times in a row with a python script and i never get the "robot answer"

What is really weird is that on my device, where Google Maps is, I've connected my main and my second Google account.
I set my second one into the configuration.yaml but it's when I've loggued my main account on Google Maps and share my location to my second account, that I received the message, on my device, to accept to share my location.
Then, on HassIO, I don't see my second account ( who is into configuration.yaml!! ) but my main...
It's not really a problem for me because the main goal was to track the device and not the second account.

Try to do the same for you and maybe it will works.
Good luck!

it depends on the account you are using and its behavioral pattern from what I remember.

@Edmond76 that is exactly how its supposed to be, you're using the "second" account to spy on yourself, so the second account is reporting your real account's spy information.

FYI, This worked for me. I was getting a NoneType exception until I changed the newly discovered device in known_devices.yaml to "track: true". As soon as I did that, it started working properly.

Was this page helpful?
0 / 5 - 0 ratings