Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn user once about missing timeouts #5434

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions requests/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import sys
import time
import warnings
from datetime import timedelta
from collections import OrderedDict

Expand All @@ -22,7 +23,8 @@
from ._internal_utils import to_native_string
from .utils import to_key_val_list, default_headers, DEFAULT_PORTS
from .exceptions import (
TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError)
TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError,
RequestsWarning)

from .structures import CaseInsensitiveDict
from .adapters import HTTPAdapter
Expand Down Expand Up @@ -358,6 +360,9 @@ class Session(SessionRedirectMixin):
'cert', 'adapters', 'stream', 'trust_env',
'max_redirects',
]

# whether the user has been warned about making requests without packet timeouts
__timeout_warned = False

def __init__(self):

Expand Down Expand Up @@ -413,7 +418,7 @@ def __init__(self):
self.adapters = OrderedDict()
self.mount('https://', HTTPAdapter())
self.mount('http://', HTTPAdapter())

def __enter__(self):
return self

Expand Down Expand Up @@ -628,6 +633,12 @@ def send(self, request, **kwargs):
if isinstance(request, Request):
raise ValueError('You can only send PreparedRequests.')

if "timeout" not in kwargs:
if not Session.__timeout_warned:
warnings.warn("Timeout missing from requests call, can hang forever",
RequestsWarning)
Session.__timeout_warned = True

# Set up variables needed for resolve_redirects and dispatching of hooks
allow_redirects = kwargs.pop('allow_redirects', True)
stream = kwargs.get('stream')
Expand Down