[英]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. 我正在使用MusixMatch API获取给定musixmatch分配的专辑ID的曲目列表。 The album id I'm using is 20903197 and I have validated it works.
我正在使用的相册ID是20903197,并且我已验证它可以正常工作。 https://playground.musixmatch.com/#!/Track/get_album_tracks_get plug that into album_id field
https://playground.musixmatch.com/#!/Track/get_album_tracks_get将其插入album_id字段
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. 但是,当我尝试使用其python sdk调用它时,所有属性的响应均为None,但返回200响应。 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?
他们的api是否可能损坏或我做错了什么?
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}}}
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. 要找到此问题的原因,需要查看Swagger Editor生成的swagger-client代码:要进行同步请求,请查看api_client.py-> __call_api ,从服务返回的结果默认情况下会反序列化,从而导致有效负载为空。
To fix it need to disable deserialization by set the param _preload_content=False . 要修复它,需要通过设置参数_preload_content = False来禁用反序列化。
Reproducing steps: 复制步骤:
Take swagger.json of MusixMatch-service on github 就拿MusixMatch服务的swagger.json在github上
Use Swagger Editor to generate python-client based on swagger.json 使用Swagger编辑器基于swagger.json生成python-client
Install the autogenerated module swagger-client 安装自动生成的模块swagger-client
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}}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.