cfangmeier / tuijam

A fancy TUI client for Google Play Music
MIT License
129 stars 9 forks source link

Unable to authenticate with Google #29

Closed RogueScholar closed 5 years ago

RogueScholar commented 5 years ago

I was excited to try this module out as tizonia has been a bit flaky for me of late, not to mention your design offers a much richer interface. Much to my chagrin though, I've never been able to get it to work. Attempting to login with no pre-existing config file leads to the error relating to using my ethernet's MAC address, which led me around in circles. So I thought I'd work around the issue by re-using the device ID I'd already created for this computer with tizonia and placing that in the tuijam config.yaml as though it had already been successfully provisioned, and now I can't get past the following fault:

> tuijam
  starting up.
  logging in.
  Traceback (most recent call last):
    File "/usr/local/bin/tuijam", line 1367, in <module>
      app = main(debug=debug)
    File "/usr/local/bin/tuijam", line 1332, in main
      if not app.login():
    File "/usr/local/bin/tuijam", line 692, in login
      credentials = self.read_config()
    File "/usr/local/bin/tuijam", line 707, in read_config
      if config['encrypted']:
  KeyError: 'encrypted'

The config.yaml file I created reads as follows:

email: <REDACTED>
password: <REDACTED>
deviceid: <REDACTED>
config_pw:
persist_queue: true
mpris_enabled: true
video: true

What is it that I'm doing incorrectly, and more importantly, how do I solve this damned Chinese fingertrap? :crying_cat_face:

cfangmeier commented 5 years ago

Hi @RogueScholar. The error is coming up because TUIJam is expecting a boolean field called encrypted in the config file. This gets written automatically during normal first time setup, but I guess since you had issues with the setup and had to write your own it's missing. In any case, I just pushed a change to make it optional so try checking out the new code and see if it works for you.

On your original problem, I think the suspect code is probably this:

    def get_device_id(self, email, password):
        if not self.g_api.login(email, password, self.g_api.FROM_MAC_ADDRESS):
            return None

        ids = [d['id'][2:] if d['id'].startswith('0x') else d['id'].replace(':', '')
               for d in self.g_api.get_registered_devices()]
        self.g_api.logout()
        try:
            return ids[0]
        except IndexError:
            print("No device ids found. This shouldn't happen...")
            return None

This is querying the google music api to get any existing device ids and just picks the first one to use in the future. If you can reproduce the error you saw, could you put the error in an additional issue?

t1meshift commented 5 years ago

My friend had the same issue, I'll contact him to try to reproduce this bug too.

t1meshift commented 5 years ago

Well, @AriosJentu couldn't authenticate with Google without 2FA. Enabling it on the account has fixed the problem. Basically, these lines

if not self.g_api.login(email, password, self.g_api.FROM_MAC_ADDRESS):
    return None

were returning None without 2FA. Still don't know why.

cfangmeier commented 5 years ago

I think this might be related to simon-weber/gmusicapi#590. The end of the thread has an alleged solution.

Walkman100 commented 5 years ago

I see you have referenced my comment, however my solution is to do with getting a correct android_id to use - it doesn't solve authenticating with 2FA, and while I don't use 2FA, you should be able to use an app-specific password in place of your password without any other modifications.

Edit: I just noticed you had issues logging in without 2FA - perhaps it's to do with the line I have before the login:

mc.__init__(debug_logging=False, validate=True, verify_ssl=True)
RogueScholar commented 5 years ago

Sorry for the extended absence, I should've gotten back to you before now to report that whatever you did cured all my issues; tuijam has been solid as a rock all this time. Well...there is one error nagging me, actually...

WARNING:googleapiclient.discovery_cache:file_cache is unavailable when using
oauth2client >= 4.0.0 or google-auth

That likes to pop itself up between the search field and the queue probably every other time I fire it up, but I don't think that's part of anything you've built. This thread would suggest the Google Devs are being brats again and breaking things for no good reason. I only mention it in case you run into it yourself or someone besides me reports it. Walk talk through life's tribulations secure in the knowledge that you are a recipient of the RogueScholar Seal of Approval from now until your final breath! (Or until the module breaks again, it's a whichever comes first kinda deal :stuck_out_tongue_winking_eye:)

I'd also be interested to learn if there's a way to queue my entire GPM Library in tuijam and I've just been too busy and too obtuse to tease it out. Honestly that's the function I use from the bona fide interface three out of four times or more: that SHUFFLE button in the upper right once you select the library tab. The fact that it's so quick to form the queue in the web interface leads me to believe that it's all done server-side through an API call, but who knows if it's exposed to the unwashed that live outside the walls of Google.

Thanks again for being so helpful and, of course, for the great app. :tophat: