跳至内容
首页Python

课程

Python 中的 API 入门

中级技能水平
更新时间 2026年1月
深入了解 API 的精彩世界,学习使用 Python 消费和处理 Web API 的基础知识。
免费开始课程
PythonProgramming
2小时
7 视频
23 道练习
1,900 XP
30,434
成就证明

创建您的免费帐户

继续使用 Google显示更多选项


继续操作即表示您接受我们的《使用条款》和《隐私政策》,并同意您的数据存储在美国。

深受数千家公司学习者的喜爱

Group

需要团队培训?

企业版试用

课程描述

深入探索 API 的精彩世界,我们将带你了解如何使用 Python 消费和处理 Web API 的基础知识。 这门课程旨在揭开 API 概念及其实践应用的神秘面纱。 它为你提供了一个实操入门,你将学习如何与 REST API 交互,并将其集成到你的应用程序或工作流程中。 在本课程结束时,你将全面了解 API,并有信心在真实场景中运用所学知识。

揭开 API 的世界

课程首先解释什么是 API,以及它们在当今数字化环境中的关键作用。 你将通过在 Python 中发起简单的 API 请求来亲自动手实践。 通过引人入胜的示例和互动练习,你将学习如何有效使用 `requests` 包与 API 进行通信。 我们将拆解 API 请求的组成,帮助你掌握请求/响应循环,并深入了解 URL、路径和参数等 HTTP 请求组件的重要性。 此外,你还将学习如何处理请求头并解读状态码,从而自信地与 API 交互。

使用 Python 掌握 REST API

我们将进入下一个层次,重点学习更高级的 API 概念。 您将了解各种身份验证方法,包括 Basic Auth 和 API 令牌,并掌握如何保护您的 API 交互。 这门课程将引导你了解发送和检索数据的细微差别,重点强调在 REST 中请求头、状态码和响应结构的重要性。 你将获得处理 JSON 数据的实践经验,从而轻松处理和发送数据。 到本章结束时,您将能够熟练地在集成 REST API 时做出明智决策,确保数据交换顺畅无阻。

先决条件

Intermediate Python for Developers
1

Making API Requests with Python

This chapter introduces Web APIs, showing you how to make your first API requests with the requests Python package. You’ll learn about the key components of an API request, HTTP verbs, and how to build URLs and send & receive data. We’ll also cover headers and status codes, using a music catalog API for practical examples. By the end of this chapter you'll be able to confidently integrate a simple REST API with Python.
开始章节
2

More API request concepts

In this chapter, you’ll learn how to authenticate with APIs, covering different methods like Basic and API key authentication using the requests package. We’ll then dive into working with structured data, focusing on requesting and handling JSON data. Finally, you’ll master error handling, including how to manage errors with requests, understand error types, and respect API rate limits.
开始章节
Python 中的 API 入门
课程完成

获得成就证明

将此证书添加到您的 LinkedIn 档案、简历或履历中
在社交媒体和绩效评估中分享
立即注册

加入超过19百万学习者,今天就开始Python 中的 API 入门!

创建您的免费帐户

继续使用 Google显示更多选项


继续操作即表示您接受我们的《使用条款》和《隐私政策》,并同意您的数据存储在美国。

通过 DataCamp for Mobile 提升您的数据技能

随时随地通过我们的移动课程和每日 5 分钟编程挑战提升技能。