The “Zen of Python” provides the basic philosophy of Python. From [PEP 20]:
> There should be one — and preferably only one — obvious way to do it.
I doubt there is a single area in Python that violates this more than making a simple HTTP request. Python provides at least six builtin libraries to do this: httplib, httplib2, urllib, urllib2, urllib3, and pycurl. There are [several] [reviews] comparing the various libraries.
But there is a third party library, [requests], that might be the “obvious way to do it” now:
import requests, json
url = ‘https://api.github.com/repos/mgalloy/mglib’
r = requests.get(url, auth=(‘mgalloy’, ‘my_password’))
requests is installed as part of [Anaconda], which an easy way to get all the core scientific programming packages for Python.
[PEP 20]: https://www.python.org/dev/peps/pep-0020/ “PEP 20”
[requests]: http://docs.python-requests.org/en/latest/ “Requests: HTTP for Humans”
[Anaconda]: https://store.continuum.io/cshop/anaconda/ “Anaconda Scientific Python Distribution”
[several]: http://isbullsh.it/2012/06/Rest-api-in-python/ “Communicating with RESTful APIs in Python”
[reviews]: https://lumberjaph.net/HTTP_requests_with_python/ “The state of HTTP’s libraries in Python”