From dc813064bbc3231250ad5f33a8511d5fff3f4643 Mon Sep 17 00:00:00 2001 From: Muhamed Fazal PS Date: Sun, 12 Jul 2026 07:29:42 +0530 Subject: [PATCH] fix: raise FileNotFoundError for missing TLS material (fixes #7564) When a TLS certificate or key file is not found, the code currently raises a generic OSError. This changes it to raise FileNotFoundError with the proper errno (ENOENT) and filename attribute, which is more specific and allows callers to catch this specific case. FileNotFoundError is a subclass of OSError, so this is backward compatible with existing code that catches OSError. --- src/requests/adapters.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/requests/adapters.py b/src/requests/adapters.py index 79ed426566..e2f04bda25 100644 --- a/src/requests/adapters.py +++ b/src/requests/adapters.py @@ -353,12 +353,12 @@ def cert_verify( conn.cert_file = cert conn.key_file = None if conn.cert_file and not os.path.exists(conn.cert_file): - raise OSError( + raise FileNotFoundError( f"Could not find the TLS certificate file, " f"invalid path: {conn.cert_file}" ) if conn.key_file and not os.path.exists(conn.key_file): - raise OSError( + raise FileNotFoundError( f"Could not find the TLS key file, invalid path: {conn.key_file}" )