Google Maps Location Sharing Cookie Issue

Hi all,

I’m having problems with the Google Maps Location Sharing component.

Edit: I should mentions that I’m running the latest HA 0.76 on hass.io

Edit 2: I have tried deleting the cookies file below, and rebooting at which point the error message I was getting changes to: Could not open pickle file, either file does not exist or no read access. and then returns to the one included below after a reboot (once the cookie file has been created).

I’ve followed the component instructions correctly as far as I can tell, and it seems to have made an .google_maps_location_sharing.cookies file, but I’m getting an error in my HA logs:

Error setting up platform google_maps

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 183, in async_setup_platform
    disc_info)
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 44, in setup_scanner
    scanner = GoogleMapsScanner(hass, config, see)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 63, in __init__
    hass.config.path(CREDENTIALS_FILE))
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 370, in __init__
    cookies_file=cookies_file)
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 194, in __init__
    if cookies_file and self._validate_cookie(cookies_file):
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 221, in _validate_cookie
    raise InvalidCookies(message)
locationsharinglib.locationsharinglibexceptions.InvalidCookies: The cookies provided do not provide a valid session.Please authenticate normally and save a valid session again

The instructions say:

Since this platform is using an unofficial API with the help of locationsharinglib, Google seems to block access to your data the first time you’ve logged in with this platform. This issue can be fixed by logging in with your new account and approving your login on the Device Activity page.

But when I visit the device activity page, there are no listings for my HA instance.

Something has gone awry here, anyone know of any solutions?

1 Like

Does the account you’ve specified use two-step verification? If so, I couldn’t find a way to make that work. I even tried creating a app password, but it still didn’t work. As far as I can tell, it only works with accounts that don’t use two-step verification. If anyone knows otherwise, I’d love to hear it.

Not sure if that’s your problem, but worth checking.

FWIW, I remember seeing the same error messages, but I can’t remember what account I was using at the time. The pickle error you will definitely see when you boot and the cookie file isn’t present. But, like you found, it creates one and then you don’t get that particular error again (unless you delete the file.)

Thanks for your suggestions

Does the account you’ve specified use two-step verification?

I’ve double checked, and 2FA isn’t enabled on this account

I’ve even gone as far as to try setting up another new account, with a more simple email address in case some of my special characters (periods/full-stops) weren’t being parsed correctly somewhere

Same here… No solution?

I tried to make the cookie file myself using the locationssharinglib python library, and the associated command line tool for generating the cookie file (I’m at work and can’t exactly remember what the tool was named) but that failed due to some problems with the library logging in to Google to start the session. From the looks of the error message, it was unable to find the HTML for the login form properly. I seem to remember hearing Google updated their login forms in the last 8 weeks, so maybe if this is true, it’s broken the library. Might be nice to ask the library author about this but I haven’t had chance yet :+1:

@costas apologies if I’ve got the wrong person, but from a quick look on these forums it looked like you were the author/maintainer of locationsharinglib. With regards to the statements in my last post on this thread, is it possible the library authentication is currently broken? Thanks in advance :ok_hand:

Could everyone with issues with the component please create an issue on the librarie’s issue tracker https://github.com/costastf/locationsharinglib/issues after having tried the library independent of HA as mentioned here https://locationsharinglib.readthedocs.io/en/latest/usage.html?

2 Likes

As per the docs, just logged into my hassbian venv, and run the following,

get-maps-cookies -e EMAIL -p PASSWORD -c COOKIES_FILE

renamed the file to .google_maps_location_sharing.cookies

restarted HA and boom, its all working again.

Thank you so much @costas

2 Likes

Thanks after reading your solution I did the same, but using hass.io/docker and it started working.

My previous attempt to generate the cookie file outside of home assistant was on another machine outside of home assistant, which was unsuccessful, but generating from the hass.io instance worked fine! Go Figure!

1 Like

I am guessing it probably has something to do with the hardware in the machine that it authorises on it, probably creates some kinda key based on whats in there, so that might be why it failed on another computer.

I am just guessing though, no real idea. Glad you got it working all ok :+1:

1 Like

I tried this (get-maps-cookies -e EMAIL -p PASSWORD -c COOKIES_FILE) on my HA run in Docker (unRAID).

However I got the following error :

pkg_resources.DistributionNotFound: The ‘beautifulsoup4==4.6.0’ distribution was not found and is required by locationsharinglib

Any ideas how to get around this?

Apologies, but I have no clue about how docker works, I am using Hassbian in a virtual environment.

Maybe @flexage might be able to help out, as it looks like he is using docker.

From a quick google, it seems to be some kinda scraping library, so it may have not been included in your docker image ? not sure on how to add it though. I dont think apt-get works in docker, but as above, I have no experience with it :frowning:

Hey @Cee thanks for your quick reply.
Do you know if I can run this on another device and transfer the cookies file? Would that work?

I don’t think you can, no, although, if you are stuck, give it a try and see. I think @flexage tried that too, and it was what caused him to fail first time, but as i say, no harm in trying.

I cannot post the same here as on a different thread, but this is what worked for me:
https://community.home-assistant.io/t/google-maps-device-tracking-setup/59944/16

Thanks after reading your solution I did the same, but using hass.io/docker and it started working.

My previous attempt to generate the cookie file outside of home assistant was on another machine outside of home assistant, which was unsuccessful, but generating from the hass.io instance worked fine! Go Figure!

How did you run get-maps-cookies in Hass.io? I have tried to ssh into it, but it doesn’t recognize the command

1 Like

Hi @flexage how did you manage to pip inside the hassio. I tried to ssh in to it but says it’s limited.