simon-weber / gmusicapi

An unofficial client library for Google Music.
https://unofficial-google-music-api.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.48k stars 257 forks source link

ValidationExceptions in search_all_access #150

Closed joharei closed 11 years ago

joharei commented 11 years ago

I'd like to report a few issues related to search_all_access()

I get this error when trying to search for something that would return no results:

2013-08-05 19:53:27,393 - gmusicapi.Mobileclient1 (shared:269) [ERROR]: the response format for Search was not recognized.

Required field 'entries' is missing

First, try the develop branch. If you can recreate this error with the most recent code please [create an issue](http://goo.gl/qbAW8) that includes the above ValidationException and the following request/response:
{'url': 'https://www.googleapis.com/sj/v1/query', 'headers': {'Authorization': '<omitted>'}, 'params': {'q': u'Apocalyptica - Fade To Black - Instrumental Version', 'max-results': 1}, 'method': 'GET'}

'{\n "kind": "sj#searchresponse"\n}\n'

A traceback follows:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/shared.py", line 248, in perform
    cls.validate(response, parsed_response)
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/mobileclient.py", line 194, in validate
    return validictory.validate(msg, cls._res_schema)
  File "/usr/lib/python2.7/site-packages/validictory/__init__.py", line 31, in validate
    return v.validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 559, in validate
    self._validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 562, in _validate
    self.__validate("_data", {"_data": data}, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 223, in validate_properties
    properties.get(eachProp))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 278, in validate_required
    None, fieldname)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 145, in _error
    raise FieldValidationError(message, fieldname, value)
ValidationException: Required field 'entries' is missing
Traceback (most recent call last):
  File "/home/johan/PycharmProjects/migrate-playlists/gmusic.py", line 83, in <module>
    gClient = GoogleMusicClient(spotify_session.ui.playlist, options.guser, options.gpass)
  File "/home/johan/PycharmProjects/migrate-playlists/gmusic.py", line 25, in __init__
    self.search_playlist(playlist)
  File "/home/johan/PycharmProjects/migrate-playlists/gmusic.py", line 63, in search_playlist
    print(self.search(song))
  File "/home/johan/PycharmProjects/migrate-playlists/gmusic.py", line 57, in search
    return self.api.search_all_access(query, 1)['song_hits'][0]
  File "/usr/lib/python2.7/site-packages/gmusicapi/clients/mobileclient.py", line 459, in search_all_access
    res = self._make_call(mobileclient.Search, query, max_results)['entries']
KeyError: 'entries'

Also, a very similar one when there would be exactly one song as result:

2013-08-05 20:10:47,468 - gmusicapi.Mobileclient1 (shared:269) [ERROR]: the response format for Search was not recognized.

Required field 'entries' is missing

First, try the develop branch. If you can recreate this error with the most recent code please [create an issue](http://goo.gl/qbAW8) that includes the above ValidationException and the following request/response:
{'url': 'https://www.googleapis.com/sj/v1/query', 'headers': {'Authorization': '<omitted>'}, 'params': {'q': u'Bigbang - Long Distance Man', 'max-results': 1}, 'method': 'GET'}

'{\n "kind": "sj#searchresponse"\n}\n'

A traceback follows:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/shared.py", line 248, in perform
    cls.validate(response, parsed_response)
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/mobileclient.py", line 194, in validate
    return validictory.validate(msg, cls._res_schema)
  File "/usr/lib/python2.7/site-packages/validictory/__init__.py", line 31, in validate
    return v.validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 559, in validate
    self._validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 562, in _validate
    self.__validate("_data", {"_data": data}, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 223, in validate_properties
    properties.get(eachProp))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 278, in validate_required
    None, fieldname)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 145, in _error
    raise FieldValidationError(message, fieldname, value)
ValidationException: Required field 'entries' is missing

And one last error that seems to an album with various artists:

2013-08-05 20:11:15,790 - gmusicapi.Mobileclient1 (shared:269) [ERROR]: the response format for Search was not recognized.

Failed to validate field 'entries' list schema: Failed to validate field 'artistId' list schema: Value u'' for list item cannot be blank'

First, try the develop branch. If you can recreate this error with the most recent code please [create an issue](http://goo.gl/qbAW8) that includes the above ValidationException and the following request/response:
{'url': 'https://www.googleapis.com/sj/v1/query', 'headers': {'Authorization': '<omitted>'}, 'params': {'q': u'Lynyrd Skynyrd - Sweet Home Alabama', 'max-results': 1}, 'method': 'GET'}

'{\n "kind": "sj#searchresponse",\n "entries": [\n  {\n   "type": "3",\n   "album": {\n    "kind": "sj#album",\n    "name": "Sweet Home Alabama: A Tribute to Lynyrd Skynyrd",\n    "albumArtist": "Various",\n    "albumArtRef": "http://lh6.ggpht.com/LFBT3pDTCKasOKdGEZY3B7gKJotn_bsqhJU88xRiymk5C8Qgqiq99y6wlj9WTgmF_DjHKtw2aA",\n    "albumId": "Bvax3jhvaf63pemwwln2irekk64",\n    "artist": "Various",\n    "artistId": [\n     ""\n    ],\n    "year": 2001\n   },\n   "score": 59.73164367675781\n  },\n  {\n   "type": "1",\n   "track": {\n    "kind": "sj#track",\n    "title": "Sweet Home Alabama",\n    "artist": "Lynyrd Skynyrd",\n    "album": "Skynyrd\'s Innyrds: Greatest Hits",\n    "albumArtist": "Lynyrd Skynyrd",\n    "year": 1989,\n    "trackNumber": 1,\n    "durationMillis": "283000",\n    "albumArtRef": [\n     {\n      "url": "http://lh5.ggpht.com/jMj9aTykDp_6P5C5ead2f9oc8zzevDtnM-S2tBDYSt0xRC7bCqgEaJKhc7xWsO42NuKbHs_B1w"\n     }\n    ],\n    "discNumber": 1,\n    "estimatedSize": "11330906",\n    "trackType": "7",\n    "storeI...'

A traceback follows:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/shared.py", line 248, in perform
    cls.validate(response, parsed_response)
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/mobileclient.py", line 194, in validate
    return validictory.validate(msg, cls._res_schema)
  File "/usr/lib/python2.7/site-packages/validictory/__init__.py", line 31, in validate
    return v.validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 559, in validate
    self._validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 562, in _validate
    self.__validate("_data", {"_data": data}, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 223, in validate_properties
    properties.get(eachProp))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 266, in validate_items
    (fieldname, old_error), fieldname, e.value)
ValidationException: Failed to validate field 'entries' list schema: Failed to validate field 'artistId' list schema: Value u'' for list item cannot be blank'

That said, I really love your project :)

simon-weber commented 11 years ago

Gotcha; thanks for reporting this. I'll fix up the schemas this afternoon.

simon-weber commented 11 years ago

Alright, those searches should all work now. Want to give them another shot and let me know how it goes?

joharei commented 11 years ago

Thanks for the quick response, that works great! I have another one for you; when I search for a song that I've given a rating, I get this:

2013-08-05 21:59:25,472 - gmusicapi.Mobileclient1 (shared:269) [ERROR]: the response format for Search was not recognized.

Failed to validate field 'entries' list schema: additional property 'rating' not defined by 'properties' are not allowed in field 'track'

First, try the develop branch. If you can recreate this error with the most recent code please [create an issue](http://goo.gl/qbAW8) that includes the above ValidationException and the following request/response:
{'url': 'https://www.googleapis.com/sj/v1/query', 'headers': {'Authorization': '<omitted>'}, 'params': {'q': u'C2C - Down The Road', 'max-results': 1}, 'method': 'GET'}

'{\n "kind": "sj#searchresponse",\n "entries": [\n  {\n   "type": "3",\n   "album": {\n    "kind": "sj#album",\n    "name": "Down The Road - A Tribute to C2C",\n    "albumArtist": "DJ Silk",\n    "albumArtRef": "http://lh5.ggpht.com/Y0rgbHf5jT1ELnfNeDs-Kv9MRYgGpmGsjOq1Qtw-riz5efpumhc7hpHYhgDVho404kqDymSO_is",\n    "albumId": "B47d2w2cavo7fw6qfy7dmnqg6mm",\n    "artist": "DJ Silk",\n    "artistId": [\n     "Awhj7l2cplqgciswr6cso7gntou"\n    ],\n    "year": 2012\n   },\n   "score": 39.82831954956055\n  },\n  {\n   "type": "1",\n   "track": {\n    "kind": "sj#track",\n    "title": "Down The Road",\n    "artist": "C2C",\n    "album": "Tetra",\n    "albumArtist": "C2C",\n    "year": 2012,\n    "trackNumber": 2,\n    "durationMillis": "207000",\n    "albumArtRef": [\n     {\n      "url": "http://lh6.ggpht.com/smNw3gZYXHGz1r0JDgPbh99p7jN4TLBiAt7dMWREzXfxCeCYuRs0QqMhAJ8HaJglyiO-uu8S9hE"\n     }\n    ],\n    "playCount": 1,\n    "discNumber": 1,\n    "rating": "5",\n    "estimatedSize": "8290252",\n    "trackType": "7",\n    "storeId"...'

A traceback follows:
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/shared.py", line 248, in perform
    cls.validate(response, parsed_response)
  File "/usr/lib/python2.7/site-packages/gmusicapi/protocol/mobileclient.py", line 194, in validate
    return validictory.validate(msg, cls._res_schema)
  File "/usr/lib/python2.7/site-packages/validictory/__init__.py", line 31, in validate
    return v.validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 559, in validate
    self._validate(data, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 562, in _validate
    self.__validate("_data", {"_data": data}, schema)
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 223, in validate_properties
    properties.get(eachProp))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 593, in __validate
    newschema.get(schemaprop))
  File "/usr/lib/python2.7/site-packages/validictory/validator.py", line 266, in validate_items
    (fieldname, old_error), fieldname, e.value)
ValidationException: Failed to validate field 'entries' list schema: additional property 'rating' not defined by 'properties' are not allowed in field 'track'