# Python requests 如何设置超时

URL: https://caijiao.org/how-to/python/requests-timeout
Source: docs/how-to/python/requests-timeout.md
Description: Python requests 如何设置超时：每个请求都传 timeout，避免脚本无限挂住。 包含脚本示例、处理提醒和相关 Python、工具内容入口。

## 快速答案

每个请求都传 timeout，避免脚本无限挂住。

```py
requests.get(url, timeout=(3, 10))
```

## 使用要点

- 请求接口时设置超时，并区分连接失败、HTTP 错误和业务错误。
- 重试只适合幂等请求，写入类接口要避免重复提交。

## 相关内容

- [Python 问题](/how-to/python/)
- [Python 教程](/python/)
- [Python 文件处理项目](/python/ch11/project-filetool)
- [正则表达式测试工具](/tool/regex-tester)
- [JSON Formatter](/tool/json-formatter)
