Error in curl::curl_fetch_memory(url, handle = handle) : Failure when receiving data from the peer
<p>I'm trying to get lyrics from the <a href="http://www.chartlyrics.com/" rel="nofollow noreferrer">chartlyrics API</a>. I write an R function that works but not inside a loop. My script is:</p>

<pre><code>library(httr)
library(RCurl)
library(XML)

df &lt;- data.frame(artist = c('Led Zeppellin', 'Adele'), song = c('Rock´n roll', 'Hello'), stringsAsFactors = F)

make.querye &lt;- function(xx) {
  names_ok &lt;- gsub(" ", "&amp;", xx)
  names_ok2 &lt;- paste("\'", names_ok, "\'", sep = '')
 querye &lt;- paste("http://api.chartlyrics.com/apiv1.asmx/SearchLyricDirect?artist=", names_ok[1],"&amp;song=",  names_ok[2], sep='')
 data &lt;- GET(querye)
 aa &lt;- content(data, "text")   
 doc &lt;- htmlParse(aa, asText=TRUE)  
 plain.text &lt;- xpathSApply(doc, "//lyric//text()[not(ancestor::script)][not(ancestor::style)][not(ancestor::noscript)][not(ancestor::form)]", xmlValue)  
 if (length(plain.text)==0) {
   plain.text2 &lt;- 'Lyrics not found'
 } else {
   plain.text2 &lt;- iconv(plain.text, from = "UTF-8", to = "latin1", sub = NA, mark = TRUE, toRaw = FALSE)  
 }
 return(plain.text2)
 }


names &lt;- c(df$artist[1], df$song[1])
make.querye(names) #- it works

names &lt;- c(df$artist[2], df$song[2])
make.querye(names) #- it also works
</code></pre>

<p>But my function doesn't work inside a loop</p>

<pre><code>for (ii in  1:2){
  names &lt;- c(df$artist[ii], df$song[ii])
  print(names)
  make.querye(names)
}
</code></pre>

<p>I get the following error:     </p>

<blockquote>
  <p>Error in curl::curl_fetch_memory(url, handle = handle) : Failure when receiving data from the peer   </p>
</blockquote>