Agent Skills
› microsoft/debugpy
› requests
requests
GitHub提供 Python Requests 库的最佳实践,涵盖会话管理、错误处理、超时设置、重试机制及安全注意事项。
Trigger Scenarios
使用 Requests 库发起 HTTP 请求
配置 HTTP 客户端连接池与认证
处理网络异常与超时逻辑
Install
npx skills add microsoft/debugpy --skill requests -g -y
SKILL.md
Frontmatter
{
"name": "requests",
"description": "Best practices for HTTP client usage with Requests including sessions, error handling, and timeouts."
}
Skill: Requests
Best practices for HTTP client usage with Requests including sessions, error handling, and timeouts.
When to Use
Apply this skill when making HTTP requests with the Requests library — sessions, auth, error handling, retries, and file uploads.
Sessions
- Use
requests.Session()for connection pooling and persistent headers/cookies across multiple requests. - Configure
session.headersfor default auth tokens and user-agent strings. - Use
session.mount()withHTTPAdapterfor retry logic.
Error Handling
- Always call
response.raise_for_status()to surface HTTP errors as exceptions. - Always set
timeout=(connect_timeout, read_timeout)— never use infinite timeouts. - Handle
requests.ConnectionError,requests.Timeout, andrequests.HTTPErrorexplicitly.
Retries
- Use
urllib3.util.RetrywithHTTPAdapterfor automatic retries with backoff. - Configure status-based retries for transient errors (429, 500, 502, 503, 504).
Security
- Never disable SSL verification (
verify=False) in production. - Pass credentials via environment variables, not hardcoded strings.
- Use
auth=parameter for HTTP auth rather than manually setting headers.
Pitfalls
- Don't forget timeouts — they default to None (infinite wait).
- Don't use
requests.get()for high-throughput — use sessions. - Close responses from streaming requests (
stream=True) to release connections.
Version History
- e5743d3 Current 2026-08-20 17:01


