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

confusing error for bad timeout value #5185

Open
bennn opened this issue Sep 4, 2019 · 0 comments
Open

confusing error for bad timeout value #5185

bennn opened this issue Sep 4, 2019 · 0 comments

Comments

@bennn
Copy link

bennn commented Sep 4, 2019

Calling requests.get(...., timeout=X) with a bad value for X causes urllib3 to throw an exception.

If X is a tuple, then requests raises its own exception too (good!).

If not, then requests doesn't say that it got a bad timeout value.

#5017 suggested a fix, but was closed

Expected Result

These two lines should both raise an exception in requests:

get("https://random.org", timeout=(True, True))
get("https://random.org", timeout=True) 

Actual Result

The first line outputs:

Traceback (most recent call last):
  File "..../requests/adapters.py", line 425, in send
    timeout = TimeoutSauce(connect=connect, read=read)
  File "..../urllib3/util/timeout.py", line 94, in __init__
    self._connect = self._validate_timeout(connect, 'connect')
  File "..../urllib3/util/timeout.py", line 121, in _validate_timeout
    raise ValueError("Timeout cannot be a boolean value. It must "
ValueError: Timeout cannot be a boolean value. It must be an int, float or None.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    get("https://random.org", timeout=(True, True))
  File "..../requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "..../requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "..../requests/sessions.py", line 537, in request
    resp = self.send(prep, **send_kwargs)
  File "..../requests/sessions.py", line 650, in send
    r = adapter.send(request, **kwargs)
  File "..../requests/adapters.py", line 431, in send
    raise ValueError(err)
ValueError: Invalid timeout (True, True). Pass a (connect, read) timeout tuple, or a single float to set both timeouts to the same value

The second outputs:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    get("https://random.org", timeout=True)
  File "..../requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "..../requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "..../requests/sessions.py", line 537, in request
    resp = self.send(prep, **send_kwargs)
  File "..../requests/sessions.py", line 650, in send
    r = adapter.send(request, **kwargs)
  File "..../requests/adapters.py", line 435, in send
    timeout = TimeoutSauce(connect=timeout, read=timeout)
  File "..../urllib3/util/timeout.py", line 94, in __init__
    self._connect = self._validate_timeout(connect, 'connect')
  File "..../urllib3/util/timeout.py", line 121, in _validate_timeout
    raise ValueError("Timeout cannot be a boolean value. It must "
ValueError: Timeout cannot be a boolean value. It must be an int, float or None.

Reproduction Steps

import requests
get("https://random.org", timeout=True) 

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.4"
  },
  "cryptography": {
    "version": "1.3.2"
  },
  "idna": {
    "version": "2.6"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.5.1"
  },
  "platform": {
    "release": "15.0.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "1000208f",
    "version": "16.0.0"
  },
  "requests": {
    "version": "2.22.0"
  },
  "system_ssl": {
    "version": "1000212f"
  },
  "urllib3": {
    "version": "1.22"
  },
  "using_pyopenssl": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant