psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
51.99k stars 9.29k forks source link

TypeError: unsupported operand type(s) for *: 'NoneType' and 'int' #2820

Closed zajalo closed 8 years ago

zajalo commented 8 years ago

I've been getting this error randomly while using RoboBrowser. RoboBrowser installs with requests 2.7.0 but I checked line 166 of current version (2.8) of retry.py and it's the same.

I should add that I made a small modification to a file in RoboBrowser as described here: https://github.com/jmcarp/robobrowser/issues/52#issuecomment-144929550

Traceback (most recent call last):
  File "fetch.py", line 139, in <module>
    go()
  File "fetch.py", line 120, in go
    result = fetch(url)
  File "fetch.py", line 29, in fetch
    browser.open(url)
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\robobrowser\browser.py", line 205, in open
    response = self.session.request(method, url, **self._build_send_args(**kwargs))
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\adapters.py", line 370, in send
    timeout=timeout
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 617, in urlopen
    release_conn=release_conn, **response_kw)
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 598, in urlopen
    retries.sleep()
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\packages\urllib3\util\retry.py", line 175, in sleep
    backoff = self.get_backoff_time()
  File "C:\Users\Vidpe\Desktop\mpb\venv\lib\site-packages\requests\packages\urllib3\util\retry.py", line 166, in get_backoff_time
    backoff_value = self.backoff_factor * (2 ** (self._observed_errors - 1))
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
Lukasa commented 8 years ago

So a quick code read suggests that this is impossible using standard requests. The backoff_factor attribute is defaulted to 0 and never assigned to None by any code in requests, as far as I can see.

However, a quick search of RoboBrowser reveals that it sets the backoff_factor, here, and in the default case will set it to None. None is not an allowed value for the backoff factor: this is a bug in RoboBrowser.