{ "cells": [ { "metadata": {}, "cell_type": "markdown", "source": "## Exercises 7 – answers\n\nThis script queries the ping endpoint 25 times, printing the count, the HTTP Status Code, and the X-RateLimit-Remaining header each time.\n\n1\\. Increase the number of loops, do you start to get 429 errors?\n\n2\\. Can you add in a step to make it wait a few seconds every iteration? Or every 100 iterations?" }, { "metadata": { "trusted": true }, "cell_type": "code", "source": "import requests, sys, time\n\nserver = \"http://rest.ensembl.org/\"\ncon = \"application/json\"\next_ping = \"/info/ping?\"\n\nx = 0\ny = 0\n\nwhile x < 1000:\n\n # submit the query\n ping = requests.get(server+ext_ping, headers={ \"Accept\" : con})\n x += 1\n y += 1\n print (\"count:\", x, \"status:\", ping.status_code, \"remaining:\", ping.headers['X-RateLimit-Remaining'])\n \n if y == 100:\n time.sleep(1)\n y = 0", "execution_count": null, "outputs": [] } ], "metadata": { "kernelspec": { "name": "python3", "display_name": "Python 3", "language": "python" }, "language_info": { "mimetype": "text/x-python", "nbconvert_exporter": "python", "name": "python", "pygments_lexer": "ipython3", "version": "3.5.4", "file_extension": ".py", "codemirror_mode": { "version": 3, "name": "ipython" } } }, "nbformat": 4, "nbformat_minor": 2 }