EXERCISE NO : 12(a)
Description:
Description:
pip is a package management system used to install and manage software packages written in Python. Many packages can be found in the Python Package Index(PyPI). Python 2.7.9 and later (on the python2 series), and Python 3.4 and later include pip (pip3 for Python 3) by default.
Pip is a recursive acronym that can stand for either "Pip Installs Packages" or "Pip Installs Python". One major advantage of pip is the ease of its command-line interface, which makes installing Python software packages as easy as issuing one command:
Write a procedure to Install packages requests, flask and explore them using pip.
pip install package-name
EXERCISE - 12(b)
Description:
The different steps involved in making request to the server is summarized below:
The different steps involved in making request to the server is summarized below:
- Make Request:
Request is made by importing the requests module.
Example:
import requests - Get the webpage using get():
r = requests.get('url')(r stands for Response object) HTTP POST request can be made using post()
r = requests.post('url', data = {'key':'value'}) - Response Content:
Content of the server's response can be read using text property.
Example:
import requests
r = requests.get('http://www.google.com') r.text - Response status code:
It can be retrieved using r.status_code. Where, r is response object. - Response headers:
Servers response headers can be viewed using r.headers. - Cookies:
These can be obtained using r.cookies['cookie name']
EXERCISE - 12(C)
Description:
It defines classes which implement the client side of the HTTP and HTTPS protocols. The different steps involving in establishing connection to the server is:- 1 Get HTTP Connection instance using httplib.HTTPConnection().
- 2 Request a web page using request() belonging to Connection instance.
- 3 Once the request is sent to the server, response is retrieved from the server usinggetresponse() returning a HTTPResponse instance.
- 4 Read the response using response instance read().
- 5 Read status of response.
- 6 Close the connection to the server.
No comments