From ec0ef7e0438a7b00ae27b18a0c01530f2c466e03 Mon Sep 17 00:00:00 2001 From: Michiel van Baak Date: Thu, 10 Jun 2021 13:41:00 +0200 Subject: [PATCH] Switch from hyper to httpx The hyper library is no longer maintained. See: https://github.com/python-hyper/hyper/commit/b77e758f472f00b098481e3aa8651b0808524d84 Their readme suggest switching to httpx Closes #32 --- gobiko/apns/client.py | 16 +++++++--------- requirements.txt | 2 +- setup.py | 4 ++-- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gobiko/apns/client.py b/gobiko/apns/client.py index 7afe967..85d4597 100644 --- a/gobiko/apns/client.py +++ b/gobiko/apns/client.py @@ -6,7 +6,7 @@ from collections import namedtuple from contextlib import closing -from hyper import HTTP20Connection +from httpx import Client from .exceptions import ( InternalException, @@ -130,7 +130,7 @@ def _get_token(self): return token def _create_connection(self): - return HTTP20Connection(self.host, force_proto=self.force_proto) + return Client(http2=True) def _create_token(self): token = jwt.encode( @@ -232,16 +232,14 @@ def _send_message(self, registration_id, alert, return response def _send_push_request(self, connection, registration_id, json_data, request_headers): - connection.request( - 'POST', - '/3/device/{0}'.format(registration_id), - json_data, + response = connection.post( + f'https://{self.host}/3/device/{registration_id}', + data=json_data, headers=request_headers ) - response = connection.get_response() - if response.status != APNSResponse.Success: - body = json.loads(response.read().decode('utf-8')) + if response.status_code != APNSResponse.Success: + body = response.json() reason = body.get("reason") if reason: diff --git a/requirements.txt b/requirements.txt index 74eafd3..8b56a5b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ cryptography==3.4.2 -hyper==0.7.0 +httpx[http2]==0.18.1 PyJWT==2.0.1 diff --git a/setup.py b/setup.py index c9b828c..35ef43a 100644 --- a/setup.py +++ b/setup.py @@ -12,13 +12,13 @@ url = 'https://github.com/genesluder/python-apns', download_url = 'https://github.com/genesluder/python-apns/tarball/0.1.6', keywords = [ - 'apns', + 'apns', 'push notifications', ], classifiers = [], install_requires=[ 'cryptography<=3.3.2', - 'hyper', + 'httpx[http2]', 'pyjwt', ], )