From 343b9e32b666d95b83af156309e6854c664c762e Mon Sep 17 00:00:00 2001 From: Phillip Verheyden Date: Thu, 2 Mar 2023 16:04:01 -0600 Subject: [PATCH] Do not force the requests module to always be included Fixes #417 --- .github/workflows/ci.yml | 26 +++++++++++++------------- .gitignore | 1 + rollbar/__init__.py | 17 ++++++++++++++--- setup.py | 20 ++++++++++---------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04373c7c..bd441c68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,18 +15,18 @@ jobs: python-version: [2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, '3.10', 3.11] framework: - FLASK_VERSION=0.12.5 Werkzeug\>=0.7,\<1.0 - - FLASK_VERSION=1.1.4 - - FLASK_VERSION=2.2.3 - - DJANGO_VERSION=1.11.29 - - DJANGO_VERSION=2.2.28 - - DJANGO_VERSION=3.2.18 - - DJANGO_VERSION=4.0.10 - - DJANGO_VERSION=4.1.7 - - TWISTED_VERSION=17.1.0 treq==16.12.0 zope.interface==4.5.0 - - TWISTED_VERSION=20.3.0 - - TWISTED_VERSION=21.7.0 - - TWISTED_VERSION=22.10.0 - - PYRAMID_VERSION=1.10.8 + - FLASK_VERSION=1.1.4 requests==2.27.1 + - FLASK_VERSION=2.2.3 requests==2.27.1 + - DJANGO_VERSION=1.11.29 requests==2.27.1 + - DJANGO_VERSION=2.2.28 requests==2.27.1 + - DJANGO_VERSION=3.2.18 requests==2.27.1 + - DJANGO_VERSION=4.0.10 requests==2.27.1 + - DJANGO_VERSION=4.1.7 requests==2.27.1 + - TWISTED_VERSION=17.1.0 treq==16.12.0 zope.interface==4.5.0 requests==2.27.1 + - TWISTED_VERSION=20.3.0 requests==2.27.1 + - TWISTED_VERSION=21.7.0 requests==2.27.1 + - TWISTED_VERSION=22.10.0 requests==2.27.1 + - PYRAMID_VERSION=1.10.8 requests==2.27.1 - STARLETTE_VERSION=0.12.13 httpx==0.18.1 python-multipart==0.0.5 - STARLETTE_VERSION=0.14.2 httpx==0.18.1 python-multipart==0.0.5 - FASTAPI_VERSION=0.40.0 httpx==0.18.1 python-multipart==0.0.5 @@ -178,7 +178,7 @@ jobs: # certifi dropped support for Python 2 in 2020.4.5.2 but only started # using Python 3 syntax in 2022.5.18. 2021.10.8 is the last release with # Python 2 support. - run: pip install certifi==2021.10.8 requests==2.27.1 incremental==21.3.0 + run: pip install certifi==2021.10.8 incremental==21.3.0 - name: Install Python 3.4 dependencies if: ${{ contains(matrix.python-version, '3.4') }} diff --git a/.gitignore b/.gitignore index f82be943..43356ec9 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Pipfile Pipfile.lock .pytest_cache/ .python-version +build diff --git a/rollbar/__init__.py b/rollbar/__init__.py index ce1552ad..c7f65f93 100644 --- a/rollbar/__init__.py +++ b/rollbar/__init__.py @@ -17,7 +17,6 @@ import wsgiref.util import warnings -import requests import six from rollbar.lib import events, filters, dict_merge, parse_qs, text, transport, urljoin, iteritems, defaultJSONEncode @@ -34,6 +33,11 @@ # 3.x import queue +try: + import requests +except ImportError: + requests = None + # import request objects from various frameworks, if available try: from webob import BaseRequest as WebobBaseRequest @@ -548,6 +552,9 @@ def send_payload(payload, access_token): payload_str = _serialize_payload(payload) if handler == 'blocking': + if requests is None: + log.error('Unable to find requests module') + return _send_payload(payload_str, access_token) elif handler == 'agent': agent_log.error(payload_str) @@ -576,11 +583,15 @@ def send_payload(payload, access_token): log.error('Unable to find async handler') return _send_payload_async(payload_str, access_token) - elif handler == 'thread': - _send_payload_thread(payload_str, access_token) elif handler == 'thread_pool': + if requests is None: + log.error('Unable to find requests module') + return _send_payload_thread_pool(payload_str, access_token) else: + if requests is None: + log.error('Unable to find requests module') + return # default to 'thread' _send_payload_thread(payload_str, access_token) diff --git a/setup.py b/setup.py index 59bde98b..830441e2 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,16 @@ 'mock<=3.0.5; python_version < "3.3"', 'enum34; python_version < "3.4"', 'httpx; python_version >= "3.6"', - 'aiocontextvars; python_version == "3.6"' + 'aiocontextvars; python_version == "3.6"', + # The currently used version of `setuptools` has a bug, + # so the version requirements are not properly respected. + # + # In the current version, `requests>= 0.12.1` + # always installs the latest version of the package. + 'requests>=0.12.1; python_version == "2.7"', + 'requests>=0.12.1; python_version >= "3.6"', + 'requests>=0.12.1; python_version == "3.5"', + 'requests>=0.12.1; python_version == "3.4"', ] setup( @@ -78,15 +87,6 @@ "Topic :: System :: Monitoring", ], install_requires=[ - # The currently used version of `setuptools` has a bug, - # so the version requirements are not properly respected. - # - # In the current version, `requests>= 0.12.1` - # always installs the latest version of the package. - 'requests>=0.12.1; python_version == "2.7"', - 'requests>=0.12.1; python_version >= "3.6"', - 'requests>=0.12.1; python_version == "3.5"', - 'requests>=0.12.1; python_version == "3.4"', 'six>=1.9.0' ], tests_require=tests_require,