From 9f718d67adefe25f6074a0b5c509cdb73b72a063 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 14 Sep 2022 16:14:45 +0300 Subject: [PATCH 1/2] Fix deprecation warning with pypa/gh-action-pypi-publish@master --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8dad013..e407e30 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -45,7 +45,7 @@ jobs: password: ${{ secrets.pypi_password }} - name: Publish package to TestPyPI - uses: pypa/gh-action-pypi-publish@master + uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.test_pypi_password }} From fbc7aa50a9f146d50ba3d7a8ea50ae37ac220715 Mon Sep 17 00:00:00 2001 From: Yomguithereal Date: Wed, 14 Sep 2022 14:23:54 +0200 Subject: [PATCH 2/2] Using a ssl context object to avoid deprecation warnings in py3 --- twitter/api.py | 10 +++++++--- twitter/stream.py | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/twitter/api.py b/twitter/api.py index 0eed604..21ec439 100644 --- a/twitter/api.py +++ b/twitter/api.py @@ -371,13 +371,17 @@ def __call__(self, **kwargs): return self._handle_response(req, uri, arg_data, _timeout) def _handle_response(self, req, uri, arg_data, _timeout=None): - kwargs = {'cafile': certifi.where()} + kwargs = {} if _timeout: kwargs['timeout'] = _timeout try: context = None - if not self.verify_context and _HAVE_SSL: - context = ssl._create_unverified_context() + if _HAVE_SSL: + if not self.verify_context: + context = ssl._create_unverified_context() + else: + context = ssl.create_default_context() + context.load_verify_locations(cafile=certifi.where()) kwargs['context'] = context handle = urllib_request.urlopen(req, **kwargs) if handle.headers['Content-Type'] in ['image/jpeg', 'image/png']: diff --git a/twitter/stream.py b/twitter/stream.py index 04efa98..19d7774 100644 --- a/twitter/stream.py +++ b/twitter/stream.py @@ -219,9 +219,13 @@ def __iter__(self): def handle_stream_response(req, uri, arg_data, block, timeout, heartbeat_timeout, verify_context=True): try: context = None - if not verify_context and _HAVE_SSL: - context = ssl._create_unverified_context() - handle = urllib_request.urlopen(req, context=context, cafile=certifi.where()) + if _HAVE_SSL: + if not verify_context: + context = ssl._create_unverified_context() + else: + context = ssl.create_default_context() + context.load_verify_locations(cafile=certifi.where()) + handle = urllib_request.urlopen(req, context=context) except urllib_error.HTTPError as e: raise TwitterHTTPError(e, uri, 'json', arg_data) return iter(TwitterJSONIter(handle, uri, arg_data, block, timeout, heartbeat_timeout))