Skip to content

request-without-timeout (S113)

Added in v0.0.213 · Related issues · View source

Derived from the flake8-bandit linter.

What it does

Checks for uses of the Python requests or httpx module without timeouts.

Why is this bad?

The timeout parameter is used to set the maximum time to wait for a response from the server. By omitting the timeout parameter or explicitly disabling it, the program may hang indefinitely while awaiting a response.

requests has no timeout by default, so both omitting the timeout argument and setting it to None are flagged. httpx applies a default timeout, so only an explicit timeout=None is flagged.

Example

import requests

requests.get("https://www.example.com/")

Use instead:

import requests

requests.get("https://www.example.com/", timeout=10)

References