1

When I visit http://musicbrainz.org/ws/2/artist/?query=artist:Sun+Ra in my web browser I get the kind of response I'm expecting.

But when I

require(httr)
GET('http://musicbrainz.org/ws/2/artist/?query=artist:Sun+Ra') -> sun.ra
content(sun.ra)
>>> NULL

the response body is empty, even though sun.ra got status 200:

Response [http://musicbrainz.org/ws/2/artist/?query=artist:Sun+Ra]
Date: 2014-10-11 17:26
Status: 200
Content-type: application/json; charset=utf-8
  <EMPTY BODY>

Does httr have a problem with "naked" XML responses?

This XML file does not appear to have any style information associated with it.


(I actually think I've figured out the answer, just still going to post the question and answer myself in case someone else has the same problem later…)

4

1 回答 1

1

It's not a problem with XML. Even though MusicBrainz doesn't require an API key, you do need to identify yourself to the service. This is easier seen with RCurl:

require(RCurl)
getURL('http://musicbrainz.org/ws/2/artist/?query=artist:Sun+Ra'
[1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?><error><text>Your requests are
    being throttled by MusicBrainz because the application you are using
    has not identified itself.  
Please update your application, and see http://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting for more information.</text><text>For usage, please see: http://musicbrainz.org/development/mmd</text></error>"
于 2014-10-11T21:36:59.070 回答