MusixMatch API响应返回200,但没有值返回JSON



我正在使用musixMatch api获取给定的曲目列表,并给定一个MusixMatch分配的相册ID。我使用的专辑ID是20903197,我已经验证了它的工作。https://playground.musixmatch.com/#!/track/get_album_tracks_get将其插入专辑_ID字段

但是,当我尝试使用他们的python sdk调用它时,我会得到所有属性的响应,但返回200响应。我在他们的网站上的Swagger上对其进行了测试,而且效果很好。他们的API是否有可能破坏或我做错了什么?

这是我当前的脚本:

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: %sn" % e

我得到了此回应:

{'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}}}

要找到此问题需要查看Swagger-client 由Swagger Editor生成的代码的原因:对于 api_client的同步回顾。py-> __call_api ,默认情况下,从服务返回的结果将导致空有效负载。

要修复它需要通过设置参数 _PRELOAD_CONTENT = false

复制步骤:

  1. swagger.json github上的musixmatch-service

  2. 使用Swagger编辑器以Swagger.json

  3. 生成Python-Client
  4. 安装自动化模块 Swagger-client

  5. 运行代码

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: %sn" % 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}}}

相关内容

  • 没有找到相关文章

最新更新