我正在尝试将以下XML查询发送到Gracenote API:
"""<QUERIES>
<AUTH>
<CLIENT>XXXXXXXXXXXXXXXXXXXXXXXX</CLIENT>
<USER>XXXXXXXXXXXXXXXXXXXXXXXXXX</USER>
</AUTH>
<QUERY CMD="ALBUM_SEARCH">
<TEXT TYPE="ARTIST">rolling stones</TEXT><TEXT TYPE="TRACK_TITLE">sympathy for the devil</TEXT><OPTION>
<PARAMETER>SELECT_EXTENDED</PARAMETER>
<VALUE>COVER,REVIEW,ARTIST_BIOGRAPHY,ARTIST_IMAGE,ARTIST_OET,MOOD,TEMPO,LINK</VALUE>
</OPTION><OPTION>
<PARAMETER>SELECT_DETAIL</PARAMETER>
<VALUE>GENRE:3LEVEL,MOOD:2LEVEL,TEMPO:3LEVEL,ARTIST_ORIGIN:4LEVEL,ARTIST_ERA:2LEVEL,ARTIST_TYPE:2LEVEL,LINK:3LEVEL</VALUE>
</OPTION><OPTION>
<PARAMETER>COVER_SIZE</PARAMETER>
<VALUE>MEDIUM</VALUE>
</OPTION>
</QUERY>
</QUERIES>"""
我通过编写以下代码来做到这一点:
import requests
import xml
xml ="""<QUERIES>
<AUTH>
<CLIENT>XXXXXXXXXXXXXXXXXXXXXXXX</CLIENT>
<USER>XXXXXXXXXXXXXXXXXXXXXXXXXX</USER>
</AUTH>
<QUERY CMD="ALBUM_SEARCH">
<TEXT TYPE="ARTIST">rolling stones</TEXT><TEXT TYPE="TRACK_TITLE">sympathy for the devil</TEXT><OPTION>
<PARAMETER>SELECT_EXTENDED</PARAMETER>
<VALUE>COVER,REVIEW,ARTIST_BIOGRAPHY,ARTIST_IMAGE,ARTIST_OET,MOOD,TEMPO,LINK</VALUE>
</OPTION><OPTION>
<PARAMETER>SELECT_DETAIL</PARAMETER>
<VALUE>GENRE:3LEVEL,MOOD:2LEVEL,TEMPO:3LEVEL,ARTIST_ORIGIN:4LEVEL,ARTIST_ERA:2LEVEL,ARTIST_TYPE:2LEVEL,LINK:3LEVEL</VALUE>
</OPTION><OPTION>
<PARAMETER>COVER_SIZE</PARAMETER>
<VALUE>MEDIUM</VALUE>
</OPTION>
</QUERY>
</QUERIES>"""
url = 'https://cXXXXXXX.web.cddbp.net/webapi/xml/1.0/'
request = request.post(url, data=xml)
为清楚起见,我在上面的代码中删除了客户ID和用户ID部分,但它们在我自己的代码中。
发布 request.text 时,我收到以下信息:
'<RESPONSES>\n <MESSAGE>GCSP: Hello error: [130] Please contact Gracenote ODP xxxxx [Name: xxxxxxxxx] [App:xxxxxxx] support.\n[Gracenote Error 130/74]</MESSAGE>\n <ERROR RETRY="N">4003</ERROR>\n <RESPONSE STATUS="ERROR">\n </RESPONSE>\n \n</RESPONSES>\n'
我感觉到错误在于我如何提交请求,但我不确定。