<jupyter_start><jupyter_text>Exercises 7 – answersThis script queries the ping endpoint 25 times, printing the count, the HTTP Status Code, and the X-RateLimit-Remaining header each time.1\. Increase the number of loops, do you start to get 429 errors?2\. Can you add in a step to make it wait a few seconds every iteration? Or every 100 iterations?<jupyter_code>library(httr)

server <- "http://rest.ensembl.org/"
con <- "application/json"
ext_ping <- "/info/ping?"

x <- 0
y <- 0

while (x < 10000) {
    ping <- GET(paste(server, ext_ping, sep = ""), accept(con))
    x = x + 1
    y = y + 1
    print( paste ("count: ", x, "status:", status_code(ping), "remaining:", headers(ping)['X-RateLimit-Remaining']))
    
    if (y == 100) {
        Sys.sleep(10)
        y <-0
    }
}<jupyter_output>[1] "count:  1 status: 200 remaining: 54999"
[1] "count:  2 status: 200 remaining: 54998"
[1] "count:  3 status: 200 remaining: 54997"
[1] "count:  4 status: 200 remaining: 54996"
[1] "count:  5 status: 200 remaining: 54995"
[1] "count:  6 status: 200 remaining: 54994"
[1] "count:  7 status: 200 remaining: 54993"
[1] "count:  8 status: 200 remaining: 54992"
[1] "count:  9 status: 200 remaining: 54991"
[1] "count:  10 status: 200 remaining: 54990"
[1] "count:  11 status: 200 remaining: 54989"
[1] "count:  12 status: 200 remaining: 54988"
[1] "count:  13 status: 200 remaining: 54987"
[1] "count:  14 status: 200 remaining: 54986"
[1] "count:  15 status: 200 remaining: 54985"
[1] "count:  16 status: 200 remaining: 54984"
[1] "count:  17 status: 200 remaining: 54983"
[1] "count:  18 status: 200 remaining: 54982"
[1] "count:  19 status: 200 remaining: 54981"
[1] "count:  20 status: 200 remaining: 54980"
[1] "count:  21 status: 200 remaining: 54979"
[1] "count:  22 status: 200 remaining: 5497[...]
{'fraction_non_alphanumeric': 0.1504719600222099, 'fraction_numerical': 0.14325374791782344, 'mean_word_length': 3.9641873278236917, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '101363', 'license': 'Apache-2.0', 'n_tokens_mistral': 844, 'n_tokens_neox': 637, 'n_words': 247, 'path': 'R/7_Rate_limiting_answers.ipynb', 'repo_name': 'fabiolib/rest-api-jupyter-course', 'size': '1801'}