New submission from Andreas Jung <aj...@users.sourceforge.net>:
Python 3.7.3 The following code is support to add a retry to the requests module. "total" is correctly initialized with 5 here but internally self.total becomes an instation of "Session" import requests from requests.adapters import HTTPAdapter from requests.packages.urllib3.util.retry import Retry def requests_retry_session( retries=5, backoff_factor=5, status_forcelist=(500, 502, 504), ): session = requests.Session() retry = Retry( total=retries, backoff_factor=backoff_factor, status_forcelist=status_forcelist, ) import pdb; pdb.set_trace() print(retry.total) adapter = HTTPAdapter(max_retries=retry) session.mount('http://', adapter) session.mount('https://', adapter) return session s = requests.Session() response = requests_retry_session(s).get('https://www.foo.com/') print(response.status_code) Traceback (most recent call last): File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/connectionpool.py", line 600, in urlopen chunked=chunked) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/connectionpool.py", line 343, in _make_request self._validate_conn(conn) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/connectionpool.py", line 839, in _validate_conn conn.connect() File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/connection.py", line 344, in connect ssl_context=context) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/util/ssl_.py", line 347, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/opt/python-3.7.3/lib/python3.7/ssl.py", line 412, in wrap_socket session=session File "/opt/python-3.7.3/lib/python3.7/ssl.py", line 853, in _create self.do_handshake() File "/opt/python-3.7.3/lib/python3.7/ssl.py", line 1117, in do_handshake self._sslobj.do_handshake() ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "bin/zopepy", line 303, in <module> exec(compile(__file__f.read(), __file__, "exec")) File "foo.py", line 28, in <module> response = requests_retry_session(s).get('https://www.foo.com/') File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/requests-2.21.0-py3.7.egg/requests/sessions.py", line 546, in get return self.request('GET', url, **kwargs) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/requests-2.21.0-py3.7.egg/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/requests-2.21.0-py3.7.egg/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/requests-2.21.0-py3.7.egg/requests/adapters.py", line 449, in send timeout=timeout File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/connectionpool.py", line 638, in urlopen _stacktrace=sys.exc_info()[2]) File "/home/ajung/sandboxes/ugent-portaal-plone-4x/eggs/urllib3-1.24.2-py3.7.egg/urllib3/util/retry.py", line 348, in increment total -= 1 TypeError: unsupported operand type(s) for -=: 'Session' and 'int' ---------- components: Library (Lib) messages: 346208 nosy: ajung priority: normal severity: normal status: open title: urllib3: TypeError: unsupported operand type(s) for -=: 'Session' and 'int' in Retry class versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37361> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com