Requests: HTTP for Humans

Standard

If you want to request data from webservers, the traditional way to do that in Python is using the urllib library. While this library is effective, you could easily create more complexity than needed when building something. Is there another way?

Requests is an Apache2 Licensed HTTP library, written in Python. It’s powered by httplib and urllib3, but it does all the hard work and crazy hacks for you.

To install type:

The Requests library is now installed. We will list some examples below:

Grabbing raw html using HTTP/HTTPS requests
We can now query a website as :

Save it and run with:

It will output the raw HTML code.

Download binary image using Python

python

An image retrieved using python

Website status code (is the website online?)

This returns 200 (OK). A list of status codes can be found here: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Retrieve JSON from a webserver 
You can easily grab a JSON object from a webserver.

HTTP Post requests using Python

SSL verification, verify certificates using Python