GithubHelp home page GithubHelp logo

costastf / locationsharinglib Goto Github PK

View Code? Open in Web Editor NEW
169.0 169.0 29.0 404 KB

A library to retrieve coordinates from an google account that has been shared locations of other accounts.

License: MIT License

Python 98.97% Shell 0.67% PowerShell 0.37%

locationsharinglib's People

Contributors

chelming avatar costastf avatar dependabot[bot] avatar dmak avatar janwillemb avatar jossef avatar jrwiebe avatar kabili207 avatar liamsaliba avatar michaelarnauts avatar pc-coholic avatar ugrug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

locationsharinglib's Issues

Exception in logout

The fetching-code seems to work fine, since I get a result. However, in the destroy, the code is logging me out, and that is giving an exception.

Exception ignored in: <bound method Service.__del__ of <locationsharinglib.locationsharinglib.Service object at 0x7f8cf3e77588>>
Traceback (most recent call last):
  File "/mnt/c/Users/micha/Development/locationsharinglib/locationsharinglib/locationsharinglib.py", line 210, in __del__
  File "/mnt/c/Users/micha/Development/locationsharinglib/locationsharinglib/locationsharinglib.py", line 206, in _logout
  File "/usr/local/lib/python3.5/dist-packages/requests-2.18.4-py3.5.egg/requests/sessions.py", line 521, in get
  File "/usr/local/lib/python3.5/dist-packages/requests-2.18.4-py3.5.egg/requests/sessions.py", line 494, in request
  File "/usr/local/lib/python3.5/dist-packages/requests-2.18.4-py3.5.egg/requests/sessions.py", line 419, in prepare_request
  File "/usr/local/lib/python3.5/dist-packages/requests-2.18.4-py3.5.egg/requests/cookies.py", line 537, in merge_cookies
  File "/usr/local/lib/python3.5/dist-packages/requests-2.18.4-py3.5.egg/requests/cookies.py", line 353, in update
  File "/usr/lib/python3.5/copy.py", line 97, in copy
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 887, in _find_spec
TypeError: 'NoneType' object is not iterable

CookieGetter object has no attribute '_initialize'

I recently noticed the module was not working as it did before, my cookies had expired. I went to run the get-maps-cookies cli tool and it throws the following error.

Traceback (most recent call last):
  File "/usr/local/bin/get-maps-cookies", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/locationsharinglib/cli.py", line 137, in main
    CookieGetter(args.email, args.password, args.cookies_file)
  File "/usr/local/lib/python3.5/dist-packages/locationsharinglib/locationsharinglib.py", line 348, in __init__
    cookies_file=cookies_file)
  File "/usr/local/lib/python3.5/dist-packages/locationsharinglib/locationsharinglib.py", line 215, in __init__
    self._authenticate()
  File "/usr/local/lib/python3.5/dist-packages/locationsharinglib/locationsharinglib.py", line 351, in _authenticate
    initial_form = self._initialize()
AttributeError: 'CookieGetter' object has no attribute '_initialize'

I'm not sure how to solve this issue.

In addition, I seem to remember that a person could theoretically get their cookies from the browser and copy and paste them into the file, is that right? I have attached a screenshot of where I think I could get the cookies, but I'm not sure which value to pick. I blacked out the values of the cookies themselves because I imagine that could be sensitive? Not sure.

Anyway, could I just copy and paste the value of one of these cookies into the contents of my cookies.conf file? Currently when I open my cookies.conf file in nano it looks like a mess of unicode errors.
cookies question

Single-factor authentication failing

Sometime in the last few days, it seems like something has changed on Google's end that prevents locationsharinglib from successfully authenticating. I'm using the locationsharinglib 3.0.11 with the following small shell script to refresh my cookie file:

#!/srv/hass/bin/python
# -*- coding: utf-8 -*-

import os
import sys

scriptFolder = os.path.dirname(os.path.realpath(__file__))
username = sys.argv[1]
password = sys.argv[2]
currentFolder = os.getcwd()
cookies_file = scriptFolder + "/" + sys.argv[3]

if os.path.isfile(cookies_file):
  os.remove(cookies_file)

from locationsharinglib import Service
service = Service(username, password, cookies_file)

for person in service.get_shared_people():
   print(person)
   print("\n")

It also fails in the exactly the same manner from Home Assistant 0.87.1. All was working last week, the last time I restarted HA.

$ refresh-google-maps-cookies.py '[email protected]' '**********' '.google_maps_location_sharing.cookies'

Traceback (most recent call last):
  File "/home/hass/config/refresh-google-maps-cookies.py", line 21, in <module>
    service = Service(username, password, cookies_file)
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 366, in __init__
    cookies_file=cookies_file)
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 225, in __init__
    self._authenticate()
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 263, in _authenticate
    self._submit_password()
  File "/srv/hass/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 306, in _submit_password
    raise InvalidCredentials(body)
locationsharinglib.locationsharinglibexceptions.InvalidCredentials:

I don't want to post all the response, because it contains personal identifying information, but the response contains "type: FIRST_AUTH_FACTOR" (I only have single-factor authentication), and "INCORRECT_ANSWER_ENTERED". I'm sure I have the correct password. I'm able to login successfully via a browser. If any other parts of the response are pertinent, I can provide them.

Including phone battery charge % to populate along with location data which get shared.

Suggestion:

From past few days I could see in the google maps "Location sharing" page there is a indication of person's current phone battery charge % and charging status as well, beside how far the person is from you.

If possible could any one please include the same as well so that i can fetch the same information in Home assistant.

Nope: I'm not a developer and i don't know what to do in order to achieve this, this was just a suggestion. Would love to hear any update on this from any one.

Unable to get it working

Iam using Python 3.6 ev
Trying to run to get the location without success.
Can you advice ? Is this example working with py ?

Also I try to use from d:\Temp\Internet\a\locationsharinglib-master\setup_aliases.ps1 - still no response nothing happend .
How can I check this lib ? How can I run this ps1 script ?
Can you paste an example ?

Thx R.

TypeError: 'NoneType' object is not iterable

I've install version 3.0.6 inside a virtual environment
Running test.py:

service = Service(username, password, 'google_maps_location_sharing.conf')
for person in service.get_all_people():
    print(person)

Output:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    for person in service.get_all_people():
  File "/home/sagi/venv/temp/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 459, in get_all_people
    people = self.get_shared_people() + [self.get_authenticated_person()]
  File "/home/sagi/venv/temp/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 420, in get_shared_people
    for info in output[0]:
TypeError: 'NoneType' object is not iterable

Username & password belongs to a new google account which I've shared my location with.
I've logged in using Firefox to the new account before running the program.

Could not load people

Home assistant installed in a virtual environment 0.70.1, python 3.5.3, debian 9.4

2018-06-03 23:36:29 DEBUG (Thread-13) [locationsharinglib.Service] Could not load people, response:

Issue with some accounts

Hello,

I'm setting this for my home assistant installation, the bug i'm having is probably not related to home assistant implementation.

I have 3 google accounts : A, B and C.
A shares its location to B and C.

When i use this library with B account : no problem
When i use this library with C account : here is what i got

2018-04-07 19:01:24 ERROR (SyncWorker_4) [locationsharinglib.Service] Response: [None, None, '0ahUKXXXXXXXXXXXXXXXZABCAE', 'ZPnXXXXXXXXXXXXXXXM', None, None, 'CNzzo9YFEXXXXXXXXXXXXXXXiPTej1Wi+jUMNTYVBYXdS0KXXXXXXXXXXXXXXXktIgY6juslw==', 1800, 1523120484424, [-869868227, [None, [None, -0.856X868, 43.855X333], 1523120352491, 12, '10 Rue tulipes, 53400 Awesome, France', None, 'FR', 7200000]], None, [0]] Traceback (most recent call last): File "/config/deps/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 292, in get_shared_people people = [Person(info) for info in output[0]] TypeError: 'NoneType' object is not iterable

B is an older account, C was created today.

Something wierd tho : on https://myaccount.google.com/device-activity page i cannot see the script accessing my C account.

2.0.2 - 2FA get-maps-cookies - TypeError: 'list' object is not an iterator

Looks like the action / form may have changed? Using get-maps-cookies on an account with 2FA enabled.

Traceback (most recent call last):
  File "/home/homer/.local/bin/get-maps-cookies", line 11, in <module>
    load_entry_point('locationsharinglib==2.0.2', 'console_scripts', 'get-maps-cookies')()
  File "/home/homer/.local/lib/python3.6/site-packages/locationsharinglib/cli.py", line 81, in main
    CookieGetter(args.email, args.password, args.cookies_file)
  File "/home/homer/.local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 310, in __init__
    cookies_file=cookies_file)
  File "/home/homer/.local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 193, in __init__
    self._authenticate()
  File "/home/homer/.local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 319, in _authenticate
    selection_form = self._skip_challenge(response)
  File "/home/homer/.local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 278, in _skip_challenge
    form = self._get_required_form(response, '/signin/challenge/skip')
  File "/home/homer/.local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 264, in _get_required_form
    if action in form.get('action')], None)
TypeError: 'list' object is not an iterator

Unable to get info of person associated with the account

When using version 3.0.6, running get_authenticated_person() returns None.

test.py

from locationsharinglib import Service
service = Service(username, password, cookies_file)
print(service.get_authenticated_person())

Output:

None

Due to this, the google account used also does not come up in get_all_people().

This works in 2.0.11

Changing User

I am using HomeAssistant, I added the google_maps platform to the Configuration file and set it all up. After the boot, the Pi requested access to my account. After changing the account to the new created user as per the install notes, the new user does not come up in the list of Device Activity and does not seem to be loaded in HA.

The strange thing is that when i look at the Device activity of the original account I entered, the last seen time was only 30min ago. This leads me to believe that the Setup has not accepted the new user credentials.

When looking at the log file I get:
Error setting up platform google_maps:
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/init.py", line 184, in async_setup_platform
disc_info)
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 36, in setup_scanner
scanner = GoogleMapsScanner(hass, config, see)
File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 55, in init
self._update_info()
File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 67, in _update_info
for person in self.service.get_all_people():
File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 292, in get_all_people
return self._get_data()
File "/usr/lib/python3.6/site-packages/cachetools/init.py", line 46, in wrapper
v = func(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 283, in _get_data
output = json.loads(response.text.split("'", 1)[1])
File "/usr/lib/python3.6/json/init.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/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)

Future exception was never retrieved, error shows up randomly after component has been setup successfully

I have the following setup:

Home assistant installed in a virtual environment 0.68.1, python 3.6.3, ubuntu 17.10

The account is setup properly as the component will be setup right. The issue is that randomly I will receive the following error that repeats itself for at least 2.5 hours:

2018-05-06 16:13:14 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.6/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.6/site-packages/locationsharinglib/locationsharinglib.py", line 324, in get_all_people
    people = self.get_shared_people() + [self.get_authenticated_person()]
  File "/srv/homeassistant/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 291, in get_shared_people
    output = self._get_data()
  File "/srv/homeassistant/lib/python3.6/site-packages/cachetools/__init__.py", line 46, in wrapper
    v = func(*args, **kwargs)
  File "/srv/homeassistant/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 285, in _get_data
    return json.loads(response.text.split("'", 1)[1])
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/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)

I see this error show up twice a minute. During the time of this error the component will not receive any updates. If I open an incognito window and navigate to https;//maps.google.com I am presented with a "are you a human" checkpoint where I have to select road signs or cars or whatever Google wants me to do. During this time the "are you a human" checkpoint shows up each time I close the incognito window, open it and navigate back to Google Maps no matter how many times I get the checkpoint right. If I restart home assistant the component will fail to setup and will not work. After a few hours I can restart home assistant again and the component will work again. It is not necessary to delete the cookies file during this time as the component will start working again after a few hours.

If there are any more details needed please let me know. I am also willing to apply any code updates on my end as well. I suspect though that any troubleshooting steps or logs needed will need to be grabbed during the time the "are you a human" checkpoint appears.

The odd part is that the last time I encountered this error it seemed to have resolved itself after 2.5 hours however if I decide to restart during this time the component will not work. Maybe there is some kind of time out?

Cross platform cookie file format

Currently the cookie file is encoded with pythons pickle dump function, requiring a Python env. to generate.

If the library supported simple text file or other encoding, it would make the use of this great library more accessible to those less familiar with python. Much like wget/curl operate.

i.e.

wget -x --load-cookies cookies.txt "https://www.google.com/maps/@40.7484986,-73.9857129,15z?hl=en"
curl --cookie cookies.txt "https://www.google.com/maps/@40.7484986,-73.9857129,15z?hl=en"

This is particularly the case with apps like Home Assistant (hass.io), where python env. is not exposed to run the mapscookiegettercli

Where the library supported a plain text file, an extensions such as Export Cookies txt could be used.

Alternatively other scripting languages could leverage the Selenium Webdriver to extract cookies.

#Credits https://tech.mavericksevmont.com/blog/powershell-selenium-automate-web-browser-interactions-part-i/
#Credits https://github.com/costastf/mapscookiegettercli

$MAPS_LOGIN = 'https://accounts.google.com/signin/v2/identifier?'`
              +'hl=en&'`
              +'passive=true&'`
              +'continue=https%3A%2F%2Fwww.google.com%2Fmaps%2F%4040.7484986%2C-73.9857129%2C15z%3Fhl%3Den&'`
              +'service=local&'`
              +'flowName=GlifWebSignIn&'`
              +'flowEntry=ServiceLogin'

$LOGGED_IN_HEURISTIC = 'Find local businesses, view maps and get driving directions in Google Maps.'


$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
if($env:PATH -notlike "*$scriptPath*") { $env:PATH += ";$scriptPath\" }

Add-Type -Path "$scriptPath\WebDriver.dll"
$ChromeDriver = New-Object OpenQA.Selenium.Chrome.ChromeDriver # Creates an instance of this class to control Selenium and stores it in an easy to handle variable

$ChromeDriver.Navigate().GoToURL($MAPS_LOGIN)
while ($ChromeDriver.PageSource -notlike "*$LOGGED_IN_HEURISTIC*" )
{ 
    Sleep -Milliseconds 500
}
$ChromeDriver.Manage().Cookies.AllCookies.GetEnumerator()

#Code to store file in json/plaintext

TypeError: 'NoteType' object is not subscriptable when authenticating with 2FA (v3.0.11)

Trying to get the new (v3.0.11) version working, to create a cookie. I run:

username='[email protected]'
password='********'
cookiesfile="[email protected]"
from locationsharinglib import CookieGetter
cg = CookieGetter(username, password, cookies_file=cookiesfile)

I get the result:

Traceback (most recent call last):
  File "test-get-cookies.py", line 7, in <module>
    cg = CookieGetter(username, password, cookies_file=cookiesfile)
  File "/home/jpl/.virtualenvs/locationsharinglib/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 359, in __init__
    cookies_file=cookies_file)
  File "/home/jpl/.virtualenvs/locationsharinglib/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 225, in __init__
    self._authenticate()
  File "/home/jpl/.virtualenvs/locationsharinglib/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 263, in _authenticate
    self._submit_password()
  File "/home/jpl/.virtualenvs/locationsharinglib/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 310, in _submit_password
    self._handle_prompt(body)
  File "/home/jpl/.virtualenvs/locationsharinglib/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 318, in _handle_prompt
    data_key = data[0][10][0][0][23]['5004'][12]
TypeError: 'NoneType' object is not subscriptable

If I hack _handle_prompt() to print out the value of "data" immediately after json decoding, it shows "None" in all of the arrays in the list.

This is what it looks like:

[['gf.sicr', None, None, 3, None, None, None, None, None, None, [[[None, None, 'TWO_STEP_VERIFICATION', 5, None, None, None, None, 4, None, 1, 1, 1, None, None, 'Firstname Lastname', '[email protected]', 'https://lh3.googleusercontent.com/-cpXahc_wJtY/AAAAAAAAAAI/AAAAAAAAAAA/randomrandomrandom/mo/photo.jpg', None, None, None, None, [], None, 8, {'1004': [None, None, None, 'myaccount.google.com/webapproval', 1, [], [], []]}], [None, None, 'TWO_STEP_VERIFICATION', 4, None, None, None, None, 5, None, 1, 1, 1, None, None, 'Firstname Lastname', '[email protected]', 'https://lh3.googleusercontent.com/-cpXahc_wJtY/AAAAAAAAAAI/AAAAAAAAAAA/randomrandomrandom/mo/photo.jpg', None, None, None, None, [], None, 8, {'1005': [[], [], None, 0]}], [None, None, 'TWO_STEP_VERIFICATION', 2, None, None, None, None, 6, None, 1, 1, 1, None, None, 'Firstname Lastname', '[email protected]', 'https://lh3.googleusercontent.com/-cpXahc_wJtY/AAAAAAAAAAI/AAAAAAAAAAA/randomrandomrandom/mo/photo.jpg', None, None, None, None, [], {'1006': ['ANDROID']}], [None, None, 'TWO_STEP_VERIFICATION', 3, None, None, None, None, 9, None, 1, 1, 1, None, None, 'Firstname Lastname', '[email protected]', 'https://lh3.googleusercontent.com/-cpXahc_wJtY/AAAAAAAAAAI/AAAAAAAAAAA/randomrandomrandom/mo/photo.jpg', None, None, None, None, [], {'1009': [' 48', 'SMS', ['SMS'], None, 'TWO_STEP_PREFERRED']}]], 1, 2, 2, None, 2, 1, None, [[8], None, None, None, 1], [None, None, None, None, 0]]], ['gf.ttu', 0, 'AHnYQLzhB-RandomRandomRandomRandom-ZbMEtKj8uWOkHKRNy-oG3WW3hU4FG2yRGmRJpyS0bnpNk7JNiMSsLAd2L1NThalG2e4TIrDGBHCVfkF7nCk_wOBFftTpP_DCkd-wuiQ-mBx0FBindfMVYT0oRcmWuU']]

I know that the first factor is working, because if I put in a bogus password, I get a different response (locationsharinglib.locationsharinglibexceptions.InvalidCredentials). I don't get any second factor prompt on my phone.

The "Usage" doco doesn't provide enough detail for me to follow, I'm afraid. And I'm not sure whether I'm doing it wrong, or if there's a change to the Google API that's breaking the lib. I'd be grateful for help in getting this working.

I assume step 1 is to create a valid cookie file, and then step 2 is to use this to get some real work done.

get-maps-cookies throwing NoExpectedFormOption

I'm receiving the following:

root@8d39e5becd4b:~# get-maps-cookies -e [redacted] -p [redacted]
Traceback (most recent call last):
  File "/usr/local/bin/get-maps-cookies", line 11, in <module>
    load_entry_point('locationsharinglib==2.0.11', 'console_scripts', 'get-maps-cookies')()
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/cli.py", line 83, in main
    CookieGetter(args.email, args.password, args.cookies_file)
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 315, in __init__
    cookies_file=cookies_file)
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 198, in __init__
    self._authenticate()
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 324, in _authenticate
    selection_form = self._skip_challenge(response)
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 283, in _skip_challenge
    form = self._get_required_form(response, '/signin/challenge/skip')
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 272, in _get_required_form
    raise NoExpectedFormOption
locationsharinglib.locationsharinglibexceptions.NoExpectedFormOption

Error setting up platform google_maps / TypeError: 'NoneType' object is not iterable

I am trying to make google_maps tracking to work on hass.io (Raspberry pi).
I get the "TypeError: 'NoneType' object is not iterable" error.

I am aware that there are a lot of mentions of this and simular issues. But all is in the closed issues and no solutions are presented.
So I open this as a new issue.

Google account

Created new google account and shared tracked user's position to the new user. Logging into maps.google.com with the new user shows the position of the tracked user.
2-factor logon have been disabled.

configuration.yaml

device_tracker:

The log

When hass.io boots I get this in the log:

Error setting up platform google_maps
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/device_tracker/__init__.py", line 184, in async_setup_platform
    disc_info)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/device_tracker/google_maps.py", line 46, in setup_scanner
    scanner = GoogleMapsScanner(hass, config, see)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/device_tracker/google_maps.py", line 66, in __init__
    self._update_info()
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/device_tracker/google_maps.py", line 78, in _update_info
    for person in self.service.get_all_people():
  File "/usr/local/lib/python3.7/site-packages/locationsharinglib/locationsharinglib.py", line 439, in get_all_people
    people = self.get_shared_people() + [self.get_authenticated_person()]
  File "/usr/local/lib/python3.7/site-packages/locationsharinglib/locationsharinglib.py", line 400, in get_shared_people
    for info in output[0]:
TypeError: 'NoneType' object is not iterable

Possible issues...

When logging into maps.google.com as the new user (on a pc), Google asks me to validate the device by sending me a text message. When I do that I get access... AND - this is despite the fact that 2-factor is disabled...

I am wondering if this could be related to the problem?

In the google account / security / your devices there is no mention of the Raspberry pi...

I hope someone can help...

Cli pipe

Trying to setup reporting location every few minutes as docker serverless image. Is there any chance to achieve that without python?

Exporting of cookies should allow specifying the filename instead of the path

When exporting the cookies, the filename should be passed as a parameter instead of the path. This allows applications that use this library to have more flexibility on what filename to use.

The code to read the cookie file is already accepting filenames, so it makes sense to also be able to export to a custom file.

TypeError: normalize() argument 2 must be str, not None

I'm using 2.0.2.
Yesterday soon after I switched to 2.0.2 Google forced me to play with captchas so I disabled google_maps tracker and re-enabled it just now. This time I get:

2018-05-09 00:00:04 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform google_maps
Traceback (most recent call last):
  File "/home/hassio/ha36/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 184, in async_setup_platform                                                                                                    
    disc_info)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/hassio/ha36/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 37, in setup_scanner                                                                                                         
    scanner = GoogleMapsScanner(hass, config, see)
  File "/home/hassio/ha36/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 56, in __init__                                                                                                              
    self._update_info()
  File "/home/hassio/ha36/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 69, in _update_info                                                                                                          
    dev_id = 'google_maps_{0}'.format(slugify(person.id))
  File "/home/hassio/ha36/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 43, in slugify
    text = normalize('NFKD', text)
TypeError: normalize() argument 2 must be str, not None

Share trip progress

Hello,
there is a new functionality in google maps to share the trip progress. This is quite useful since provide also an ETA.
Could you get this new value for the ETA? It woul be nice to use it to update the NEST thermostat with the ETA to home.

Thanks!

Home asistant 0.73

Hi , latest version of HA is not compatible having a requirement issue with your library

locationsharinglib 2.0.7 has requirement requests==2.18.4, but you'll have requests 2.19.1 which is incompatible.

could this be looked ?

Accuracy is parsed wrong

The field that is currently is extracted as accuracy is not the real accuracy. Google maps pinned me exact on the location where I am, but the lib is reporting an accuracy of 1500.

Unexpected location sharing data being returned

It seems the object being returned by Service._get_data() is not in the format the library expects. This is what I see when I enable logging and try the example in USAGE.rst:

Response: [None, None, '[41-char alphanumeric string]', '[23-char alphanumeric string]', None, None, '[17-char alphanumeric string ending in ==]', 1800, 1522032173486, None, None, [0]]
Traceback (most recent call last):
  File "/Users/jrwiebe/locate/env/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 284, in get_shared_people
    people = [Person(info) for info in output[0]]
TypeError: 'NoneType' object is not iterable
Response: [None, None, '[same 41 chars]', '[same 23 chars]', None, None, '[same 17 chars]', 1800, 1522032173486, None, None, [0]]
Traceback (most recent call last):
  File "/Users/jrwiebe/locate/env/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 297, in get_authenticated_person
    output[9][1],
TypeError: 'NoneType' object is not subscriptable

I hesitate to share the contents of those three semi-redacted strings without knowing what they contain. The Google login appears successful.

[Edited: I initially described the redacted strings as base64, but I only meant that's what they resembled. Of course if that's what they were, I'd know how to decode them.]

Ratelimits on Polling too often

Does Google have any documentation available for polling too often? I am currently running the script every 5 minutes and was wondering if I would be violating any ratelimits.

Google Maps location sharing not updated

I'm getting this error in Hass.io 0.69.1

2018-05-13 14:24:50 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform google_maps
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 184, in async_setup_platform
    disc_info)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 36, in setup_scanner
    scanner = GoogleMapsScanner(hass, config, see)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 55, in __init__
    self._update_info()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 68, in _update_info
    dev_id = 'google_maps_{0}'.format(slugify(person.id))
  File "/usr/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 43, in slugify
    text = normalize('NFKD', text)
TypeError: normalize() argument 2 must be str, not None

and I get no update from it after Hass.io restart.

Service does not seem to retrieve anything

When I instantiate the Service class, no data seems to be retrieved; e.g.:

service.get_all_people()
()

I've considered that this may be related to my security settings; when I instantiate the service, I get a push notification on my phone asking if this is me (and I say yes). I've also tried stealing my cookie jar from Firefox and dumping it to a file, then telling Service to use that file, but I get the same result - no error on instantiation, but no data, either. Presumably it is not successfully logging on, but I'm not sure how to verify that yet.

get-maps-cookies fails

I have 2FA setup on my a/c. When trying to create a cookie, I get this:

File "/home/jpl/.virtualenvs/locationsharinglib/local/lib/python2.7/site-packages/locationsharinglib/locationsharinglib.py", line 334, in _handle_prompt
data_key = soup.find('div', {'data-api-key': True}).get('data-api-key')

My phone pops up a message asking if it was me, so that's nice. But still the error, and no cookie.

Memory not so good, but I /think/ the first attempt had my phone pop up a prompt asking me to choose between three two-digit numbers, which I cancelled. Since then, the above error, no numbers to choose, and just the "was this you?" prompt.

Character encoding error in self.address

Hello.

I think there's a character encoding problem in self.address:

Traceback (most recent call last):
File "../../locationsharinglib/test.py", line 6, in
print(person)
File "/opt/locationsharinglib/locationsharinglib/locationsharinglib.py", line 108, in str
'Current location :{}'.format(self.address),
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 28: ordinal not in range(128)

Not sure if related but adresses concerned are located in France.

list index out of range when getting authenticated user

Service.get_authenticated_user() is returning None for me. When I dig a little, it turns out that line 165 is catching an IndexError from the line 146. When I print out the output returned from _get_data(), it only has length 9. Not really sure what is going on here. Seems like I am not getting enough data back from Google?

NoExpectedFormOption when logging into any other account

I have a successful authentication and cookie file from one user account on my gsuite domain. I wanted to switch to a different user for location tracking, but I am unable to authenticate for any other user on my domain using get-maps-cookies. I have verified that the non-working accounts do not have 2FA enabled.

Unsure how to troubleshoot from here, as all accounts are set up the same way. 1 works, the other 2 do not.

Just a note regarding usage, I am trying to get this working for my local installation of HomeAssistant.

Exact command being used:
sudo get-maps-cookies -e USERNAME -p PASSWORD -c cookies.cookies

Unable to dump cookies

The code to dump the cookies is not working since the file descriptor is not opened in binary mode.

from locationsharinglib import Service

service = Service('[email protected]', 'xxxxx')
service.export_session('samples')

Throws the following error:

Traceback (most recent call last):
  File "samples/test.py", line 5, in <module>
    service.export_session('samples')
  File "/home/michael/Development/locationsharinglib/locationsharinglib/locationsharinglib.py", line 211, in export_session
    pickle.dump(self._session.cookies, cookie_file)
TypeError: write() argument must be str, not bytes

This can be fixed by opening the cookies.pickle file as wb instead of just w.

    def export_session(self, path):
        """Exports the session's cookies to the provided path

        Args:
            path: The path to save the cookies.pickle file

        Returns:
            True on success.

        """
        cfile = os.path.join(path, 'cookies.pickle')
        with open(cfile, 'wb') as cookie_file: # <- this line
            pickle.dump(self._session.cookies, cookie_file)
            return True

Noob

I've got Hassio on a PI and access to macs and pcs.

Would it be easiest to run this from a mac to get the cookie and then put it on the pi?

Hassio doesn't seem to let you run python stuff.

Cookies file does not get created by get-maps-cookies

I have v2.0.11 installed, and an account with 2FA. When I run get-maps-cookies, it doesn't create a cookies file, whether I specify the cookie filename or leave it to choose the default. I know that it authenticates me correctly because a) if bombs out if I use the wrong password, and b) my phone prompts me to confirm that it was me.

I've tried letting the sample script create the cookies file, which it does, but then the next time I run the script, it doesn't like the cookies file.

Error setting up platform google maps

I have not been able to get google maps presence detection to work. I am using hassio on a Rasberry Pi 3. I get the following error. I have also tried life 360 and get a similar error.
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 205, in _validate_cookie self._session.cookies = pickle.load(cfile) EOFError: Ran out of input

Can you create a new tag for example 3.0.10

Hi, I saw that you have updated the code. I want to push the new code to my home assistant. The current version with the old code is 3.0.9. Can you create a new tag for example 3.0.10 ?
Thanks in advance!

Only 1 devices showing - possible change on the Google side

Hi I've been using locationsharinglib in my script for sometime without issue. I am using it to track 2 devices that share their location with a dedicated location sharing Google account. In the last week or so (maybe longer) it is only showing 1 of the devices. The other device isn't showing up. If I log in to this account using a browser I can see both devices perfectly.

Any ideas what could be causing the issue?

InvalidData exception after update

I recently upgraded from 2.0.11 to 3.0.3, and now I'm receiving the following error:

Traceback (most recent call last):
[omitted irrelevant portion of stack]
File "C:\Users\Will\davis.tox\py36-prod-plat_windows\lib\site-packages\locationsharinglib\locationsharinglib.py", line 459, in get_all_people
people = self.get_shared_people() + [self.get_authenticated_person()]
File "C:\Users\Will\davis.tox\py36-prod-plat_windows\lib\site-packages\locationsharinglib\locationsharinglib.py", line 451, in get_authenticated_person
None,
File "C:\Users\Will\davis.tox\py36-prod-plat_windows\lib\site-packages\locationsharinglib\locationsharinglib.py", line 95, in init
self._populate(data)
File "C:\Users\Will\davis.tox\py36-prod-plat_windows\lib\site-packages\locationsharinglib\locationsharinglib.py", line 113, in _populate
raise InvalidData
locationsharinglib.locationsharinglibexceptions.InvalidData

Nothing has changed except the version, and downgrading again eliminates the exception.

Can't Get Google Tracker to Work

Been spending a little time trying to configure the Google Tracker platform without much success.

The only reference that I see within the logs is:

[homeassistant.loader] Loaded device_tracker.google_maps from homeassistant.components.device_tracker.google_maps
[homeassistant.components.device_tracker] Setting up device_tracker.google_maps

The .google_maps_location_sharing.cookies is created in the HA config folder and a coupe of times I received messages on my phone asking if I was trying to login from another computer. However I do not see any API requests on my google account which would lead me to believe that HA is not being successful in trying to login to the dummy account that my phone is sharing my location with.

When I login to the dummy account I don't see anything under 'Device Activity' apart from the manual login that I did before trying to get this running.

Not quite sure where I go from here!

Improve reliability

Google keeps on marking the logins as suspicious, I guess due to missing useragents or other things.
After a few tries, it asks additional details before the login succeeds.

UnboundLocalError: local variable 'data' referenced before assignment

Version 2.0.7

When running this in a python3 console:

from locationsharinglib import Service
service = Service('[email protected]', 'password', cookies_file='.google_maps_location_sharing.cookies')
for person in service.get_all_people():
    print(person)

I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 393, in get_all_people
    people = self.get_shared_people() + [self.get_authenticated_person()]
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 360, in get_shared_people
    output = self._get_data()
  File "/usr/local/lib/python3.6/site-packages/cachetools/__init__.py", line 46, in wrapper
    v = func(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/locationsharinglib/locationsharinglib.py", line 354, in _get_data
    return data
UnboundLocalError: local variable 'data' referenced before assignment

What gives?

Excessive amount of error 500

I'm using this library (v2.0.11) via Home Assistant. My log sees a LOT of error messages that look like this:

Unable to parse response :<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 500 (Server Error)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>500.</b> <ins>That’s an error.</ins>
  <p>The server encountered an error and could not complete your request.<p>If the problem persists, please <A HREF="http://www.google.com/support/">report</A> your problem and mention this error message and the query that caused it.  <ins>That’s all we know.</ins>
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/locationsharinglib/locationsharinglib.py", line 389, in _get_data
    data = json.loads(response.text.split("'", 1)[1])
IndexError: list index out of range

They seem to come in bunches. It would be really nice to at least more gracefully handle this exception, like write a small error message to the log that says something like the server could not satisfy the query or something. As it is it looks like the code doesn't expect this to happen.

It would be even nicer if it could filter out some of the consecutive messages. I did this with one of my HA components. I.e., if the same error happens twice in a row, say in the error message that further errors will not be shown until the errors stop. Then when the query works again, write a message saying things are ok again (maybe even giving a count of how many consecutive errors happened.)

Bottom line, though, is my log gets flooded with these messages and which makes it hard to see other problems that might be happening.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.