<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 HTTP requests
In this tutorial ti is covered how to make requests via HTTP protocol. 
For more informations about related stuff see
Step1:  The variable data contains returned HTML code (full page) as string. You can process it, save it, or do anything else you need.
Requests
Example how to get static content of web page with Requests follows.
Step2:  Get JSON data from an API
This task is demonstrated on Open Notify - an open source project that provides a simple programming interface for some of NASA’s awesome data.
The examples bellow cover how to obtain current possition of ISS. With Requests library it is possible to get the JSON from the API in the same way as HTML data.
Step3:  The Requests function json() convert the json response to Python dictionary. In next code block is demonstrated how to get data from obtained response.
Persistent session with Requests
Session with Requests are handy for cases where you need to use same cookies (session cookies for example) or authentication for multiple requests.
Step4:  Compare the output of the code above, with the example bellow.
Step5:  Custom headers
Headers of the response are easy to check, example follows.
Step6:  The request headers can be modified in simple way as follows.
<ASSISTANT_TASK:>
Python Code:
from urllib.request import urlopen
r = urlopen('http://www.python.org/')
data = r.read()
print("Status code:", r.getcode())
Explanation: HTTP requests
In this tutorial ti is covered how to make requests via HTTP protocol. 
For more informations about related stuff see:
* <a href="https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">Hypertext Transfer Protocol (HTTP)</a>
* <a href="https://en.wikipedia.org/wiki/JSON">JavaScript Object Notation</a>
* <a href="https://en.wikipedia.org/wiki/HTML">HyperText Markup Language (HTML)</a>
Keep in mind, that in this tutorial we work only with static content. How to obtain web dynamic content is not covered in this tutorial. If you want to deal with dynamic content, study <a href="http://selenium-python.readthedocs.io/">Selenium Python Bindings</a>.
Get HTML page content
In this section are examples how to get HTTP response with two different libraries:
* <a href="https://docs.python.org/3.4/library/urllib.html?highlight=urllib">urllib</a> (standard library in Python 3)
* <a href="http://docs.python-requests.org/en/master/">Requests</a> (instalable through pip)
In this tutorial is mainly used the Requests library, as a prefered option.
Urlib2 library
Example how to get static content of web page with Urlib2 follows:
End of explanation
import requests
r = requests.get("http://www.python.org/")
data = r.text
print("Status code:", r.status_code)
Explanation: The variable data contains returned HTML code (full page) as string. You can process it, save it, or do anything else you need.
Requests
Example how to get static content of web page with Requests follows.
End of explanation
import requests
r = requests.get("http://api.open-notify.org/iss-now.json")
obj = r.json()
print(obj)
Explanation: Get JSON data from an API
This task is demonstrated on Open Notify - an open source project that provides a simple programming interface for some of NASA’s awesome data.
The examples bellow cover how to obtain current possition of ISS. With Requests library it is possible to get the JSON from the API in the same way as HTML data.
End of explanation
s = requests.Session()
print("No cookies on start: ")
print(dict(s.cookies))
r = s.get('http://google.cz/')
print("\nA cookie from google: ")
print(dict(s.cookies))
r = s.get('http://google.cz/?q=cat')
print("\nThe cookie is perstent:")
print(dict(s.cookies))
Explanation: The Requests function json() convert the json response to Python dictionary. In next code block is demonstrated how to get data from obtained response.
Persistent session with Requests
Session with Requests are handy for cases where you need to use same cookies (session cookies for example) or authentication for multiple requests.
End of explanation
r = requests.get('http://google.cz/')
print("\nA cookie from google: ")
print(dict(r.cookies))
r = requests.get('http://google.cz/?q=cat')
print("\nDifferent cookie:")
print(dict(r.cookies))
Explanation: Compare the output of the code above, with the example bellow.
End of explanation
r = requests.get("http://www.python.org/")
print(r.headers)
Explanation: Custom headers
Headers of the response are easy to check, example follows.
End of explanation
headers = {
    "Accept": "text/plain",
}
r = requests.get("http://www.python.org/", headers=headers)
print(r.status_code)
Explanation: The request headers can be modified in simple way as follows.
End of explanation
<END_TASK>