Skip to Content
Python入门指南, 3rd Edition
book

Python入门指南, 3rd Edition

by Bill Lubanovic
September 2025
Intermediate to advanced
660 pages
7h 15m
Chinese
O'Reilly Media, Inc.
Content preview from Python入门指南, 3rd Edition

第24章 网络

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

哦,我们编织了一张多么纠结的网...

沃尔特-司各特,"马尔米恩

横跨 法国和瑞士边境的 是欧洲核子研究中心(CERN)--一个多次粉碎原子以确保安全的粒子物理研究机构。所有这些撞击都会产生大量数据。1989 年,英国科学家 蒂姆-伯纳斯-李(Tim Berners-Lee)首先在欧洲核子研究中心内部分发了一份提案,以帮助在该中心和整个研究界传播信息。他将 称为万维网,并将 的设计提炼为三个简单的理念:

超文本传输协议 (HTTP)

网络客户端和服务器交换请求和响应的协议

超文本标记语言(HTML)

结果的显示格式

统一资源定位器(URL)

唯一表示服务器和服务器上资源的方法

在最简单的用法中,网络客户端(伯纳斯-李是第一个使用浏览器这一术语的人)通过 HTTP 连接到网络服务器,请求 URL 并接收 HTML。这一切都建立在Network+ 的网络基础之上,而当时的 Network+ 是非商业性的,只有少数大学和研究机构知道。

他在 NeXT 计算机上编写了第一个网络浏览器和服务器。1 1993 年, ,伊利诺伊大学的一群学生发布了 Mosaic2 浏览器(适用于 Windows、Macintosh 和 Unix)和美国国家超级计算应用中心(NCSA)的httpd服务器。

那年夏天,我下载了 Mosaic 并开始建立网站,当时我还不知道网络和互联网很快就会成为日常生活的一部分。 那时,互联网仍是官方的非商业性网络,世界上已知的网络服务器大约有五百台。

到 1994 年底,网络服务器的数量已经增长到 10,000 台。 互联网开始向商业用途开放,Mosaic 的作者们创办了 Netscape,编写商业网络软件。 Netscape 在早期的互联网狂潮中上市,网络的爆炸式增长从未停止过。

几乎所有的计算机语言都被用来编写 Web 客户端和 Web 服务器。 动态语言 Perl、PHP 和 Ruby 尤为流行。 在本章中,我将说明为什么 Python 是一种特别适用于各个层次的网络工作的语言:

  • 客户端,用于访问远程网站

  • 服务器,为网站和网络 API 提供数据

  • 网络 API 和服务,用于以可浏览网页以外的方式交换数据

网络基础知识

互联网的低级网络管道称为传输控制协议/互联网协议,或更常见的简称为 TCP/IP(参见"TCP/IP")。 它在计算机之间移动字节,但并不关心这些字节的含义。 这是高级协议的工作--用于特定目的的语法定义。HTTP 是网络数据交换的标准协议。

网络是一个客户端-服务器系统,客户端向服务器发出请求:客户端打开 TCP/IP 连接,通过 HTTP 发送 URL 和其他信息,并接收响应

响应的格式也由 HTTP 规定,包括请求的状态,以及(如果请求成功)响应的数据和格式。

最著名的网络客户端是网络浏览器。 它可以通过多种方式发出 HTTP 请求。 您可以在定位栏中输入 URL 或点击网页中的链接,手动发起请求。 通常,返回的数据用于显示网站(HTML 文档、JavaScript 文件、CSS 文件和图像),但也可以是任何类型的数据,而不仅仅是用于显示的数据。

HTTP 的一个重要方面是它的无状态性。 你建立的每个 HTTP 连接都与其他连接无关。 这简化了基本的网络操作,但也使其他操作变得复杂。 以下是一些挑战的例子:

缓存

网络客户端应保存不会更改的远程内容,以避免再次从服务器下载。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

生成式人工智能设计模式

生成式人工智能设计模式

Valliappa Lakshmanan, Hannes Hapke

Publisher Resources

ISBN: 9798341668898