current position:Home>Python computer network basics

Python computer network basics

2022-01-30 11:25:51 Little cute in the circle of friends

Little knowledge , Great challenge ! This article is participating in “ A programmer must have a little knowledge ” Creative activities .

This article has participated in  「 Digging force Star Program 」 , Win a creative gift bag , Challenge creation incentive fund .

Preface

In our daily life , The Internet is everywhere , Whether we use mobile phones or computers , They can't do without the support of the network . The Internet connects us to all parts of the world , Shorten the distance between people , Enjoy the ocean of network information at any time .

We don't just use the Internet, we bring convenience , We should also think about the following problems :

How the Internet works ?

Next , Let's learn the basic knowledge of computer network ,Let's go~

Python The network library

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

  • Python The built-in library provides urllib、request modular
  • Python It also supports the third module :selenium、aiohttp、phantomjs

TCP/IP A network model

OSI Seven layer model

name explain
application layer An interface that provides network services for network programs
The presentation layer Transform the upper data or information , Ensure that the application understands
The session layer Responsible for establishing 、 management 、 Terminate the session between processes
Transport layer Be responsible for providing end-to-end transmission of upper layer data segments , Represents the device gateway
The network layer Responsible for routing packets between subnets , Represents the device router
Data link layer Package the data of the network layer , Or analyze the physical layer data and transfer it to the network layer . Represents a device switch
The physical layer Pass the data analysis to the data link layer , Or package the data transmitted by the data link layer and transmit it to the hardware equipment for transmission . Represents the device network card 、 A hub

TCP/IP The network model has four layers :

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

URL

URL(Uniform Resource Locator) Object represents the uniform resource locator .

Web page request mode

In the process of network request, it is mainly divided into Request and Response

  • Request: Request to play the requested access to the server
  • Response: After the server receives the request from the client , The server verifies the validity of the request , Query the requested content and return it to the client .

The network requestor is GET and POST

  • GET: The most common way to request , The transmitted data is displayed in URL in , And there are restrictions on the size of data transmission
  • POST:URL Do not display transmitted data ,, Transfer parameters in form , You can query and modify information

GET and POST Key points

  1. GET and POST The network layer is used TCP agreement
  2. GET Only one... Is generated in the network request TCP package ,POST In the whole network 2 individual TCP package

GET In a request , hold HEADER And data are transmitted to the server at one time ,POST Then transmit first HEADER To server , The server returns to 100 after , Then continue to send data to the server , return 200.

HTTP and HTTPS

HTTP: Hypertext transfer protocol , Belongs to the application layer protocol , Commonly used in web Transfer information between browser and server

HTTPS: Hypertext transfer security protocol , By using SSL/TSL Encryption technology and HTTP The protocol is combined to transmit network data safely

HTTP and HTTPS difference :

  1. HTTP Agreement default TCP The protocol port is 80,HTTPS The agreement is TCP agreement 443 port
  2. HTTP Protocol transmission is plaintext transmission ,HTTPS Before protocol transmission SLL Encrypt data
  3. HTTP Protocol page response ratio HTTPS fast ,HTTP Agreement needs to be 3 individual TCP package ,HTTPS Transmitting data requires 12 individual TCP package

HTTP Status code

Status code explain
2XX success
200 The request is successful
201 close POST command
202 Received for processing , But the processing is not complete
203 Return some information
204 No response , Request received , But there is no information to return
3xx Redirect
300 Multiple Choices Customer requested documents can be found in multiple locations
301 Moved — The requested data has a new location and the change is permanent
302 Already found — The requested data is temporarily different URL.
304 not changed — The document was not modified as expected .
4xx Error in the client
400 Wrong request — There is a syntax problem in the request
401 unauthorized — Client is not authorized to access data
403 prohibit — Even if you have authorization, you don't need access to
5xx Error in the server
500 internal error — Because of an accident , The server could not complete the request
502 Bad Gateway — The server received an invalid response from the upstream server
505 I won't support it HTTP edition

Commonly used tools

What we usually use most in debugging is Postman

Postman The tools are very powerful , It can not only simulate the interface request of each protocol , It also supports script running such as batch triggering

Postman Official website documentation tutorial

summary

In this issue , We mainly understand Python Support network programming related modules , And learn the basic knowledge related to computing network

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

The above is the content of this issue , Welcome big guys to praise and comment , See you next time ~

copyright notice
author[Little cute in the circle of friends],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201301125487568.html

Random recommended