requests

bởi microsoft

Các phương pháp tốt nhất cho việc sử dụng HTTP client với Requests bao gồm sessions, xử lý lỗi và thời gian chờ.

npx skills add https://github.com/microsoft/debugpy --skill requests

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.headers for default auth tokens and user-agent strings.
  • Use session.mount() with HTTPAdapter for 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, and requests.HTTPError explicitly.

Retries

  • Use urllib3.util.Retry with HTTPAdapter for 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.

Thêm skills từ microsoft

oss-growth
microsoft
Cá tính tăng trưởng OSS
official
winapp-ui-automation
microsoft
Kiểm tra và tương tác với giao diện ứng dụng Windows đang chạy từ dòng lệnh bằng UI Automation (UIA). Sử dụng khi một tác nhân AI hoặc nhà phát triển cần kiểm tra giao diện người dùng...
official
accessibility-aria-expert
microsoft
Phát hiện và sửa các vấn đề về khả năng tiếp cận trong giao diện web React/Fluent UI. Sử dụng khi xem xét mã để đảm bảo tương thích với trình đọc màn hình, sửa nhãn ARIA, đảm bảo…
official
generate-canvas-app
microsoft
[DEPRECATED — sử dụng canvas-app thay thế] Tạo một ứng dụng canvas Power Apps hoàn chỉnh.
official
django
microsoft
Các phương pháp tốt nhất cho phát triển web Django bao gồm models, views, templates và testing.
official
github-issue-creator
microsoft
Chuyển đổi ghi chú thô, nhật ký lỗi, ghi âm giọng nói hoặc ảnh chụp màn hình thành báo cáo vấn đề markdown sắc nét theo phong cách GitHub. Sử dụng khi người dùng dán thông tin lỗi, lỗi…
official
python-package-management
microsoft
Sử dụng uv để quản lý phụ thuộc và poethepoet để tự động hóa tác vụ.
official
runtime-validation
microsoft
Xác thực thời gian chạy cho các ứng dụng đã di chuyển — bao gồm chiến lược kiểm thử (giai đoạn lập kế hoạch) và thực thi kiểm thử (giai đoạn xác thực): xác minh khởi động,…
official