pythonapiswagger-codegenmusixmatch

Musixmatch api response returning 200 but returning json with None values


I'm using the MusixMatch API to get a list of tracks given a musixmatch assigned album id. The album id I'm using is 20903197 and I have validated it works. https://playground.musixmatch.com/#!/Track/get_album_tracks_get plug that into album_id field

However, when I try calling it using their python sdk I'm getting a response with None for all the attributes but returning 200 response. I tested it on the swagger on their website and it works fine. Is it possible their api is broken or am I doing something wrong?

This is my current script:

import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint


swagger_client.configuration.api_key['apikey'] = 'API_KEY_HERE'



api_instance = swagger_client.TrackApi()
album_id = '20903197' # str | The musiXmatch album id
format = 'json' # str | output format: json, jsonp, xml. (optional) (default to json)
callback = 'callback_example' # str | jsonp callback (optional)
f_has_lyrics = 'f_has_lyrics_example' # str | When set, filter only contents with lyrics (optional)
page = 3.4 # float | Define the page number for paginated results (optional)
page_size = 3.4 # float | Define the page size for paginated results.Range is 1 to 100. (optional)

try:
    api_response = api_instance.album_tracks_get_get(album_id, format=format, callback=callback, f_has_lyrics=f_has_lyrics, page=page, page_size=page_size)
    pprint(api_response)
except ApiException as e:
    print "Exception when calling TrackApi->album_tracks_get_get: %s\n" % e

and I'm getting this response:

{'message': {'body': {'track_list': [{'album_coverart_100x100': None,
                                      'album_coverart_350x350': None,
                                      'album_coverart_500x500': None,
                                      'album_coverart_800x800': None,
                                      'album_id': None,
                                      'album_name': None,
                                      'artist_id': None,
                                      'artist_mbid': None,
                                      'artist_name': None,
                                      'commontrack_id': None,
                                      'commontrack_vanity_id': None,
                                      'explicit': None,
                                      'first_release_date': None,
                                      'has_lyrics': None,
                                      'has_subtitles': None,
                                      'instrumental': None,
                                      'lyrics_id': None,
                                      'num_favourite': None,
                                      'primary_genres': None,
                                      'restricted': None,
                                      'secondary_genres': None,
                                      'subtitle_id': None,
                                      'track_edit_url': None,
                                      'track_id': None,
                                      'track_isrc': None,
                                      'track_length': None,
                                      'track_mbid': None,
                                      'track_name': None,
                                      'track_name_translation_list': None,
                                      'track_rating': None,
                                      'track_share_url': None,
                                      'track_soundcloud_id': None,
                                      'track_spotify_id': None,
                                      'track_xboxmusic_id': None,
                                      'updated_time': None}]},
             'header': {'available': 1.0,
                        'execute_time': 0.0039160251617432,
                        'status_code': 200.0}}}

Solution

  • To find the reason this problem need to look at code of swagger-client generated by Swagger Editor: for a sync-request look at api_client.py -> __call_api, the result returned from service is deserialized by default that leads to an empty payload.

    To fix it need to disable deserialization by set the param _preload_content=False.

    Reproducing steps:

    1. Take swagger.json of MusixMatch-service on github

    2. Use Swagger Editor to generate python-client based on swagger.json

    3. Install the autogenerated module swagger-client

    4. Run code

    import swagger_client
    from swagger_client.rest import ApiException
    import json
    
    
    configuration = swagger_client.Configuration()
    configuration.api_key['apikey'] = '..'
    
    api_instance = swagger_client.TrackApi(swagger_client.ApiClient(configuration))
    album_id = 20903197
    
    try:
        api_response = api_instance.album_tracks_get_get(album_id, _preload_content=False)
        result = json.loads(api_response.data)
        print(result)
    except ApiException as e:
        print("Exception when calling TrackApi->album_tracks_get_get: %s\n" % e)
    
    # result: {u'message': {u'body': {u'track_list': [{u'track': {u'track_share_url': u'https://www.musixmatch.com/lyrics/Kaskade-feat-Ilsey/Disarm-You?utm_source=application&utm_campaign=api&utm_medium=1982%3A1409612089803', u'album_name': u'Disarm You (feat. Ilsey)', u'has_subtitles': 1, u'track_name': u'Disarm You (feat. Ilsey)', u'primary_genres': {u'music_genre_list': [{u'music_genre': {u'music_genre_parent_id': 34, u'music_genre_name_extended': u'Dance', u'music_genre_vanity': u'Dance', u'music_genre_id': 17, u'music_genre_name': u'Dance'}}]}, u'album_id': 20903197, u'explicit': 0, u'has_lyrics': 1, u'artist_name': u'Kaskade feat. Ilsey', u'track_id': 84384445, u'instrumental': 0, u'updated_time': u'2015-10-16T17:38:45Z', u'track_rating': 21, u'commontrack_id': 46959082, u'restricted': 0, u'num_favourite': 773, u'artist_id': 28754430, u'track_name_translation_list': [], u'has_richsync': 1, u'track_edit_url': u'https://www.musixmatch.com/lyrics/Kaskade-feat-Ilsey/Disarm-You/edit?utm_source=application&utm_campaign=api&utm_medium=1982%3A1409612089803'}}]}, u'header': {u'available': 1, u'status_code': 200, u'execute_time': 0.0088551044464111}}}