Search code examples
pythonjenkinspython-requestsjenkins-pipelineurllib3

Jenkins Job Failing for urllib3: ValueError: Timeout value connect was <object object at 0x7efe5adb9aa0>, but it must be an int, float or None


As of May 4, 2023, at 16:00, I started seeing one of our Jenkins job failing with the following error:

Traceback (most recent call last):
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 822, in get_info
     return json.loads(self.jenkins_open(
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 560, in jenkins_open
     return self.jenkins_request(req, add_crumb, resolve_auth).text
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 576, in jenkins_request
     self.maybe_add_crumb(req)
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 373, in maybe_add_crumb
     response = self.jenkins_open(requests.Request(
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 560, in jenkins_open
     return self.jenkins_request(req, add_crumb, resolve_auth).text
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 579, in jenkins_request
     self._request(req))
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/jenkins/__init__.py", line 553, in _request
     return self._session.send(r, **_settings)
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/requests/sessions.py", line 701, in send
     r = adapter.send(request, **kwargs)
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/requests/adapters.py", line 483, in send
     timeout = TimeoutSauce(connect=timeout, read=timeout)
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/urllib3/util/timeout.py", line 119, in __init__
     self._connect = self._validate_timeout(connect, "connect")
   File "/home/jenkins/agent/workspace/my-jenkins-job/.tox/appdev-ci-staging/lib/python3.9/site-packages/urllib3/util/timeout.py", line 156, in _validate_timeout
     raise ValueError(
 ValueError: Timeout value connect was <object object at 0x7efe5adb9aa0>, but it must be an int, float or None.

As nothing had changed on my side in my configuration, it looks like an upstream issue.

I was using requests Python library in my job and requests uses urllib3.

How can we fix this?


Solution

  • A new version 2.0.2 of urllib3 was released on May 4, 2023, which can be seen here: urllib3 2.0.2 - Release history

    As my job installs the Python libraries in the beginning of the job using pip in a virtual Python environment, it started installing the latest version of urllib3 which had some issues. So, it is looks an upstream issue.

    I fixed it by adding urllib3>=1.26.15,<2 in my requirements.txt file.