Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.

This paper has participated inProject DigginTo win the creative gift package and challenge the creative incentive money.

preface

In our daily life, the Network is everywhere, no matter we use mobile phones or computers, can not leave the support of the network. The Internet connects us to all parts of the world, shortens the distance between people, and enjoys the ocean of Internet information at any time.

Not only do we use the Internet for the convenience we bring, but we also need to think about the following questions:

How does the network work?

Let’s go to the computer network

Python network library

Python, as one of the high-level languages, also supports modules related to network programming.

  • Python’s built-in libraries provide urllib and Request modules
  • Python also supports a third module: Selenium, AIoHTTP, phantomJS

TCP/IP network model

👉 OSI seven-layer model

The name of the instructions
The application layer Provides an interface to a network service for a network program
The presentation layer Transform upper-level data or information to ensure that the application can understand it
The session layer Responsible for establishing, managing, and terminating sessions between processes
The transport layer Responsible for segmenting the upper layer data to provide end-to-end transmission, representing the device gateway
The network layer Is responsible for routing data packets between subnets on behalf of the device router
Data link layer Package the data at the network layer, or parse the physical layer data to the network layer. Representative Device switch
The physical layer The data is parsed to the data link layer, or the data transmitted by the data link layer is packaged and transmitted to the hardware device for transmission. Represents the device network card and hub

👉TCP/IP network model has four layers:

The name of the agreement
The application layer SMTP, FTP, DNS, SNMP, NFS, HTTP, TELNET
The transport layer TCP, UDP
The network layer ICMP, IGMP, IP, ARP, RARP
Network interface layer LAN, WAN, MAN

URL

👉 Uniform Resource Locator (URL) object represents Uniform Resource Locator.

Page request mode

👉 can be divided into Request and Response during network Request

  • Request: Sends requests to the server
  • Response: After receiving the request from the client, the server verifies the validity of the request and returns it to the client based on the query of the request content.

💡 The network requester is GET and POST

  • GET: The most common request mode. The transmitted data is displayed in the URL and the data transfer size is limited
  • POST: indicates that the URL does not display the transmitted data. The URL is sent as a form to query and modify the information

🔔GET and POST highlights

  1. Both the GET and POST network layers use TCP
  2. GET generates only one TCP packet in a network request, whereas POST generates two TCP packets in the entire network

GET Sends the HEADER and data to the server once in a request. POST sends the HEADER to the server first. After the server returns 100, it sends more data to the server, returning 200.

HTTP and HTTPS

HTTP: hypertext transfer protocol. It is an application-layer protocol used to transfer information between web browsers and servers

HTTPS: a hypertext transfer security protocol that uses THE SSL/TSL encryption technology and HTTP to secure network data transmission

Differences between HTTP and HTTPS:

  1. The default HTTP port is TCP port 80, and HTTPS port is TCP port 443
  2. HTTP data is transmitted in plain text. SLL encryption is required before HTTPS data is transmitted
  3. The HTTP page responds faster than HTTPS. HTTP requires three TCP packets, and HTTPS requires 12 TCP packets for data transmission

The HTTP status code

Status code instructions
2XX successful
200 The request is successful
201 Immediately following the POST command
202 Received for processing, but processing is incomplete
203 Return partial information
204 No response, request received, but no information to return
3xx redirect
300 The documentation for the Multiple Choices customer request can be found in Multiple locations
301 Moved – The requested data has a new location and the change is permanent
302 Found – Requested data temporarily has a different URL.
304 Unmodified – The document is not modified as expected.
4xx An error occurred in the client
400 Incorrect request – There is a syntax problem in the request
401 Unauthorized – Unauthorized client access to data
403 Forbid – Access is not required even if authorized
5xx An error occurred in the server
500 Internal error – The server was unable to complete the request due to unexpected circumstances
502 Error Gateway – The server received an invalid response from the upstream server
505 The HTTP version is not supported

Commonly used tools

Postman is usually the one we use most during debugging

The Postman tool is powerful enough not only to simulate interface requests for various protocols, but also to support script runs such as batch triggering

Postman official website documentation tutorial

conclusion

In this installment, we’ll take a look at the Python modules that support network programming and learn the basics of computing networks

Next we will start to learn Python network programming related module methods

That’s the content of this episode. Please give us your thumbs up and comments. See you next time