导航菜单

第三方库

学习常见Python第三方库的使用方法

85%
网络请求 (requests)

使用 requests 发送 HTTP 请求

展示GET和POST请求示例,并处理响应和异常。
import requests

# 发送GET请求
response = requests.get('https://api.github.com/repos/psf/requests')
print(response.status_code)
data = response.json()
print(data['stargazers_count'], 'stars')

# POST请求示例
payload = {'key': 'value'}
response = requests.post('https://httpbin.org/post', json=payload)
print(response.json())