stevenleeg / geemusic

A bridge between Google Music and Amazon's Alexa
GNU General Public License v3.0
664 stars 181 forks source link

Not Streaming music - There was a problem with the requested skill's response #269

Closed tinba12 closed 5 years ago

tinba12 commented 5 years ago

I have been able to use Gee music to get information. For example If I say "ask gee music List the latest albums by The Wonder Years" it does work. If I say "Ask gee music Play music by A Tribe Called Quest" I get There was a problem with the requested skill's response. Response json is

{ "body": { "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "Playing top tracks by A Tribe Called Quest" }, "card": { "type": "Standard", "title": "Playing top tracks by A Tribe Called Quest", "text": "", "image": { "smallImageUrl": "https://lh3.googleusercontent.com/muiawPgKoepzV5sjK5HxKcPzg1N34sGvqNLZIRisvwoa6dJ1pD_EbBVF6syo6f5Uh5rRxbR20A", "largeImageUrl": "https://lh3.googleusercontent.com/muiawPgKoepzV5sjK5HxKcPzg1N34sGvqNLZIRisvwoa6dJ1pD_EbBVF6syo6f5Uh5rRxbR20A" } }, "directives": [ { "type": "AudioPlayer.Play", "playBehavior": "REPLACE_ALL", "audioItem": { "stream": { "token": "7d1fc7a6-8040-4785-bbff-e76a28ebc6df", "url": "https:///<server>/alexa/stream/Txcshosrdbqfmim7fmh47f43yyi", "offsetInMilliseconds": 0 } } } ], "shouldEndSession": true }, "sessionAttributes": {} } }

If I go to https:////alexa/stream/Txcshosrdbqfmim7fmh47f43yyi I get this error

gmusicapi.exceptions.CallFailure gmusicapi.exceptions.CallFailure: GetStreamUrl: 403 Client Error: Forbidden for url: https://mclients.googleapis.com/music/mplay?opt=hi&net=mob&pt=e&slt=1542658057781&sig=ObGgrk-mSaIeidwMHRio3PsAoyk&mjck=Txcshosrdbqfmim7fmh47f43yyi&hl=en_US&dv=0&tier=aa (requests kwargs: {'method': 'GET', 'url': 'https://mclients.googleapis.com/music/mplay', 'allow_redirects': False, 'headers': {'X-Device-ID': 'ECA86BFB2251', 'Authorization': '<omitted>'}, 'params': {'opt': 'hi', 'net': 'mob', 'pt': 'e', 'slt': '1542658057781', 'sig': b'ObGgrk-mSaIeidwMHRio3PsAoyk', 'mjck': 'Txcshosrdbqfmim7fmh47f43yyi', 'hl': 'en_US', 'dv': 0, 'tier': 'aa'}})

tinba12 commented 5 years ago

I have fixed the gmusicapi.exceptions.CallFailure error. Still have to first error though

mvanholstyn commented 5 years ago

@tinba12 did you get this working? I hit the same issue today.

fergyfresh commented 5 years ago

This is weird because this looks like a valid response.

{ "body": { "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "Playing top tracks by A Tribe Called Quest" }, "card": { "type": "Standard", "title": "Playing top tracks by A Tribe Called Quest", "text": "", "image": { "smallImageUrl": "https://lh3.googleusercontent.com/muiawPgKoepzV5sjK5HxKcPzg1N34sGvqNLZIRisvwoa6dJ1pD_EbBVF6syo6f5Uh5rRxbR20A", "largeImageUrl": "https://lh3.googleusercontent.com/muiawPgKoepzV5sjK5HxKcPzg1N34sGvqNLZIRisvwoa6dJ1pD_EbBVF6syo6f5Uh5rRxbR20A" } }, "directives": [ { "type": "AudioPlayer.Play", "playBehavior": "REPLACE_ALL", "audioItem": { "stream": { "token": "7d1fc7a6-8040-4785-bbff-e76a28ebc6df", "url": "https:///<server>/alexa/stream/Txcshosrdbqfmim7fmh47f43yyi", "offsetInMilliseconds": 0 } } } ], "shouldEndSession": true }, "sessionAttributes": {} } }
fergyfresh commented 5 years ago

Can you try any of these other utterances that might work? I'd love for you to science for me ;)

                "Play artist {artist_name}",
                "Play songs by {artist_name}",
                "Play top songs by {artist_name}",
                "Play top tracks by {artist_name}",
                "Play music by {artist_name}",
                "Play tracks by {artist_name}"
tinba12 commented 5 years ago

I tried "ask gee music play artist lupe fiasco" I get the same error. The below is the response. { "body": { "version": "1.0", "response": { "outputSpeech": { "type": "PlainText", "text": "Playing top tracks by Lupe Fiasco" }, "card": { "type": "Standard", "title": "Playing top tracks by Lupe Fiasco", "text": "", "image": { "smallImageUrl": "https://lh3.googleusercontent.com/TfO3gSHcOjshuPeEo9mLymYOh4gHAXx23Q1CA25K8Jth_RkH87qw6wfA87brDcj-9xEvn7xb", "largeImageUrl": "https://lh3.googleusercontent.com/TfO3gSHcOjshuPeEo9mLymYOh4gHAXx23Q1CA25K8Jth_RkH87qw6wfA87brDcj-9xEvn7xb" } }, "directives": [ { "type": "AudioPlayer.Play", "playBehavior": "REPLACE_ALL", "audioItem": { "stream": { "token": "cb8fa496-9ac5-43b5-be87-14fbe2cfb86a", "url": "https:///<Server>/alexa/stream/T2rzpdf6viys76x4q7z3luq4evy", "offsetInMilliseconds": 0 } } } ], "shouldEndSession": true }, "sessionAttributes": {} } }

fergyfresh commented 5 years ago

Is that an error?

tinba12 commented 5 years ago

Same error as above. There was a problem with the requested skill's response

tinba12 commented 5 years ago

That is the server response to alexa.

RickeyWard commented 5 years ago

You also get this message if you don't tell the alexa skill that it has "audio player" on the interfaces.

RickeyWard commented 5 years ago

Though, that just gets you past the "there was a problem with the response" issue. It doesn't make your audio play. Google is throwing back a forbidden, looks like the gmusic library isn't able to get the audio stream from google.

2018-12-01T23:10:41.046334+00:00 app[web.1]: 10.13.252.86 - - [01/Dec/2018 23:10:41] "GET /alexa/stream/Txrlu3maxeyxamtea24gpbvsj7a HTTP/1.1" 500 - 2018-12-01T23:10:41.046597+00:00 app[web.1]: Traceback (most recent call last): 2018-12-01T23:10:41.046599+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__ 2018-12-01T23:10:41.046601+00:00 app[web.1]: return self.wsgi_app(environ, start_response) 2018-12-01T23:10:41.046602+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app 2018-12-01T23:10:41.046603+00:00 app[web.1]: response = self.handle_exception(e) 2018-12-01T23:10:41.046605+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception 2018-12-01T23:10:41.046606+00:00 app[web.1]: reraise(exc_type, exc_value, tb) 2018-12-01T23:10:41.046607+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise 2018-12-01T23:10:41.046609+00:00 app[web.1]: raise value 2018-12-01T23:10:41.046610+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app 2018-12-01T23:10:41.046611+00:00 app[web.1]: response = self.full_dispatch_request() 2018-12-01T23:10:41.046612+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request 2018-12-01T23:10:41.046614+00:00 app[web.1]: rv = self.handle_user_exception(e) 2018-12-01T23:10:41.046615+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception 2018-12-01T23:10:41.046616+00:00 app[web.1]: reraise(exc_type, exc_value, tb) 2018-12-01T23:10:41.046617+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise 2018-12-01T23:10:41.046618+00:00 app[web.1]: raise value 2018-12-01T23:10:41.046619+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request 2018-12-01T23:10:41.046620+00:00 app[web.1]: rv = self.dispatch_request() 2018-12-01T23:10:41.046621+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request 2018-12-01T23:10:41.046623+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args) 2018-12-01T23:10:41.046624+00:00 app[web.1]: File "/app/geemusic/controllers.py", line 43, in redirect_to_stream 2018-12-01T23:10:41.046625+00:00 app[web.1]: stream_url = api.get_google_stream_url(song_id) 2018-12-01T23:10:41.046626+00:00 app[web.1]: File "/app/geemusic/utils/music.py", line 153, in get_google_stream_url 2018-12-01T23:10:41.046628+00:00 app[web.1]: return self._api.get_stream_url(song_id) 2018-12-01T23:10:41.046629+00:00 app[web.1]: File "<decorator-gen-102>", line 2, in get_stream_url 2018-12-01T23:10:41.046630+00:00 app[web.1]: 2018-12-01T23:10:41.046631+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gmusicapi/utils/utils.py", line 293, in wrapper 2018-12-01T23:10:41.046632+00:00 app[web.1]: return function(*args, **kw) 2018-12-01T23:10:41.046633+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gmusicapi/clients/mobileclient.py", line 388, in get_stream_url 2018-12-01T23:10:41.046635+00:00 app[web.1]: return self._make_call(mobileclient.GetStreamUrl, song_id, device_id, quality) 2018-12-01T23:10:41.046636+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gmusicapi/clients/shared.py", line 84, in _make_call 2018-12-01T23:10:41.046637+00:00 app[web.1]: return protocol.perform(self.session, self.validate, *args, **kwargs) 2018-12-01T23:10:41.046638+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gmusicapi/protocol/shared.py", line 226, in perform 2018-12-01T23:10:41.046639+00:00 app[web.1]: raise CallFailure(err_msg, call_name) 2018-12-01T23:10:41.046641+00:00 app[web.1]: gmusicapi.exceptions.CallFailure: GetStreamUrl: 403 Client Error: Forbidden for url: https://mclients.googleapis.com/music/mplay?opt=hi&net=mob&pt=e&slt=1543705840934&sig=OBN2w5wmgNDyUO5wRBnFcVMBbw4&mjck=Txrlu3maxeyxamtea24gpbvsj7a&hl=en_US&dv=0&tier=aa 2018-12-01T23:10:41.046642+00:00 app[web.1]: (requests kwargs: {'method': 'GET', 'url': 'https://mclients.googleapis.com/music/mplay', 'allow_redirects': False, 'headers': {'X-Device-ID': '661C0BF6C446', 'Authorization': '<omitted>'}, 'params': {'opt': 'hi', 'net': 'mob', 'pt': 'e', 'slt': '1543705840934', 'sig': b'OBN2w5wmgNDyUO5wRBnFcVMBbw4', 'mjck': 'Txrlu3maxeyxamtea24gpbvsj7a', 'hl': 'en_US', 'dv': 0, 'tier': 'aa'}}) 2018-12-01T23:10:41.046644+00:00 app[web.1]: (response was: '<HTML>\n<HEAD>\n<TITLE>Forbidden</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Forbidden</H1>\n<H2>Error 403</H2>\n</BODY>\n</HTML>\n')

RickeyWard commented 5 years ago

This is because the deviceid is now validated, you can get them from your account.

fergyfresh commented 5 years ago

I think you meant *not validated. Some things work with the gmusicapi and some dont. There is work being done on the gmusicapi side to harden this a bit so we wont have so many errors on our end.

On Sat, Dec 1, 2018, 7:24 PM DiamondDrake notifications@github.com wrote:

This is because the deviceid is now validated, you can get them from your account.

ā€” You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/stevenleeg/geemusic/issues/269#issuecomment-443470103, or mute the thread https://github.com/notifications/unsubscribe-auth/AJN8ODomOOXRuNKIjTdPTHOJEMZ1inc4ks5u0x2ugaJpZM4Ypz2q .

tinba12 commented 5 years ago

I have the audio interface enabled. My Device id is valid. When I say "ask gee music List the latest albums by The Wonder Years" I a get proper response.

fergyfresh commented 5 years ago

You might have to use this https://www.myfakeinfo.com/mobile/get-android-device-information.php grab the MAC Address field and try to login with that and ur app password on a computer. Then it might fail in the terminal and then you can see the list of the actual valid IDs. That is what I have to do ONCE if I'm using a new PAAS since most PAAS/IAAS platforms dont give you access to a mac address.

tinba12 commented 5 years ago

@fergyfresh I already did that. The stream URL works if you enter it into a browser.

RickeyWard commented 5 years ago

I can get it to work, but google flags my account as "suspicious" and the music will only play for 2ish minutes. @tinba12 if you can get the audio stream in the browser and youre getting valid data back from the api, then it's your alexa side. Make sure you have rebuild your model since adding the audio player, and that you're on SSL.

fergyfresh commented 5 years ago

Are you using 2FA? This smells like you're not using 2FA.

RickeyWard commented 5 years ago

Are you using 2FA? This smells like you're not using 2FA.

If you're referring to me, I am. You can't create app passwords unless you're using 2FA. I get emails that says "we blocked some suspicious activity on your account"

fergyfresh commented 5 years ago

Are you using a device I'd?

On Mon, Dec 3, 2018, 5:44 PM DiamondDrake notifications@github.com wrote:

Are you using 2FA? This smells like you're not using 2FA.

If you're referring to me, I am. You can't create app passwords unless you're using 2FA. I get emails that says "we blocked some suspicious activity on your account"

ā€” You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/stevenleeg/geemusic/issues/269#issuecomment-443899330, or mute the thread https://github.com/notifications/unsubscribe-auth/AJN8OPzjprl2UBq9ICMRIHQc9cp0Lm-Pks5u1alRgaJpZM4Ypz2q .

tinba12 commented 5 years ago

Looking through the debug I found this

"request": { "type": "SessionEndedRequest", "requestId": "amzn1.echo-api.request.0f9f08e1-fe1c-4a98-b0b8-96caf1e6ff9f", "timestamp": "2018-12-04T02:11:13Z", "locale": "en-US", "reason": "ERROR", "error": { "type": "INVALID_RESPONSE", "message": "The URL specified in the Play directive is invalid" } }

fergyfresh commented 5 years ago

@tinba12 can you get any debug logs from the server (geemusic). the debug logs here are from Alexa.

fergyfresh commented 5 years ago

@RickeyWard do this on a terminal on your computer: Go to this website https://www.myfakeinfo.com/mobile/get-android-device-information.php and get the alphanumeric in the MAC Address field. I'm going to reference that as android_id below. Whatever your workflow get the pip requirements from this project installed and go into a python shell:

from gmusicapi import Mobileclient
api = Mobileclient()
email = 'youremail'
password='yourapppassword'
android_id=android_id # i talked about this above.
api = api.login(email, password, android_id)

I hope this will fail and give you the valid device ids that are tied to your account. If you then set an environment variable on your server called ANDROID_ID to the alphanumeric string you needed to set to login correctly without an exception, you should no longer get the suspicious activity issue.

The maintainer of gmusicapi has since reworked this since Google cracked down AGAIN on our workaround of the unnofficial API so I haven't worked that workflow into this app yet.

fergyfresh commented 5 years ago

I actually just did it and it's surprisingly simple. It's some not trivia rework, but we could do it. Maybe on a feature branch. I think I could get this done this week at some point.

I figured it out. With some work I could use this avenue instead of email+app password+device id setup. Make sure that when you clone you end up

git clone https://github.com/simon-weber/gmusicapi
cd gmusicapi
virtualenv .venv -p python3.6
source .venv/bin/activate
pip install -r requirements.txt
python

then in the python shell

from gmusicapi import Mobileclient
api = Mobileclient()
a = api.perform_oauth()
# follow the link provided in the shell
# and paste that long string into the prompt.
api.oauth_login('blakadfladfhla')
# this will exception out and dump a list of things we want that are preceded by
# a * at the end exception string
api.oauth_login('alphanumeric_string_from_the_bottom_of_the_exception')

we could use this method instead of having to store you app password and email in the server and also this would theoretically save us from random google logouts. So in https://github.com/stevenleeg/geemusic/blob/master/geemusic/utils/music.py#L14 we would use api.oauth_login instead of api.login and would only use the device_id command line arg.

everyonce commented 5 years ago

can someone spell out for me how to authorize with a mobile device id? I've gotten a few steps down the path but I'm not sure if I'm doing the right things...

fergyfresh commented 5 years ago

@everyonce does the above comment not work for you? If that's not what you meant, I think in order to get a mobile device id auth'd you have to physically download google play music and login to that app on your phone.

RickeyWard commented 5 years ago

I started pulling the latest gmusicapi a couple days ago, but I was not sure what the steps were needed to do an oath signin, though I'm using heroku so getting to a popup redirect is a bit of an issue. Generating a token and putting that in the environment should work.

everyonce commented 5 years ago

ok, so I think that's where I'm lost - I've got a phone using gmusic, but how do I use the token(s) from the phone app when I'm running geemusic on my server?

fergyfresh commented 5 years ago

@RickeyWard @everyonce I added how to do it via the develop branch of this repo. I also got the tests passing, so its working for me.

The gist of it is to do this: python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print(m.perform_oauth());'

Followed by this: python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print(m.oauth_login("<device_id>")); print(m.get_all_songs()[0])'

When you do the second command it should exception out and spit out a list of device id's and from that list replace above with one of those. then it should work. then you need to use my develop branch of this repo and use ONLY the environment variable DEVICE_ID, since we no longer need GOOGLE_EMAIL and GOOGLE_PASSWORD.

TLDR: Get the DEVICE_ID from the two code snippets above and use this branch https://github.com/stevenleeg/geemusic/tree/develop instead of master.

everyonce commented 5 years ago

ok, I did eventually get it running using that info, tyvm! However, I was able to confirm the streaming command used isn't allowed for free accounts: gmusicapi.exceptions.NotSubscribed: Store tracks require a subscription to stream. (https://goo.gl/v1wVHT)

tinba12 commented 5 years ago

This is the log when i run ask gee music play songs by asia debug.txt

fergyfresh commented 5 years ago

What do you have as the callback url in the Alexa skills console? @tinba12 APP_URL + '/alexa' is what it should be.

steveseguin commented 5 years ago

My god. It works. (finally, lol). šŸ‘

I had several device_ids listed after that "python -c 'from gmusicapi import Mobileclient ..." step, some long and some short. Using the last device_id in the list, a long one, didn't work for me-- I got a forbidden error when trying to play a song with it. I then went thru the steps again and used a short device_id; for whatever reason this time it worked.

Fantastic. I am using the development branch, ubuntu, python 3.6, and paid Google Music.

Thank you.

fergyfresh commented 5 years ago

Congrats! I want to merge this into master, but I don't wanna break stuff that was already working for people until @stevenleeg gives it a go.

tinba12 commented 5 years ago

Here is a picture of my endpoint. image 3

troycurtisjr commented 4 years ago

I'd like to note that the only way I was able to get geemusic to work for me was to use oauth (and a copied DEVICE_ID from my Android device). I could never get it to authenticate using an app password.