Voip.ms latency measurement, Part 1 =================================== Contents -------- .. toctree:: :maxdepth: 1 Indices and tables ------------------ * :ref:`genindex` * :ref:`modindex` * :ref:`search` Background ---------- Welcome to the second app project! This time, the goal is to get server hostnames from voip.ms, ping them, and graph the latency over time. Exercise -------- For this week, the goal is to create an api querying function that does the following: * It should query the voip.ms api to get a list of servers as a json structure. * Here is the url to use, no modification required: `https://voip.ms/api/v1/rest.php?api_username=pythonedustudent@gmail.com&api_password=Kqmqa9xmqe&method=getServersInfo` * It will return a json structure where two keys are of interest to us: * status, which should be "success" unless something went wrong. * servers, which is a nested dictionary. * It should return the server host names as a list of strings. This will require using the :py:mod:`requests` package. :py:func:`requests.get` to query the api, :py:func:`requests.json` to decode the response. On completion of this exercise, you should be able to run your stub program and have it do the following: * Print a list of voip.ms server hosts if the query succeeds. * Print an error and exit if one occurs. * Terminate itself cleanly. Hints ----- To help you get started, here is a sample function definition: .. literalinclude:: voip1.py :language: python3 :lines: 9-13 To find out what keys are useful in the response from the voip api you can use Pycharm's debugger. Create the code to query the api, and set a breakpoint at the next line. Then when you run in debug, the program execution will stop right after that call, and you can use the Variables view in the debugger to look through the dictionary. Solution -------- When you are ready to see one possible solution, try :download:`this file `