diff --git a/pyproject.toml b/pyproject.toml index 385519d..4cceb55 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ classifiers = [ ] requires-python = ">=3.8" dependencies = [ + "requests", "pycryptodome", "bitarray" ] diff --git a/uid2_client/identity_map_client.py b/uid2_client/identity_map_client.py index 6466685..2065cd0 100644 --- a/uid2_client/identity_map_client.py +++ b/uid2_client/identity_map_client.py @@ -36,5 +36,5 @@ def generate_identity_map(self, identity_map_input): req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc), identity_map_input.get_identity_map_input_as_json_string().encode()) resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req) - resp_body = parse_v2_response(self._client_secret, resp.read(), nonce) + resp_body = parse_v2_response(self._client_secret, resp.text, nonce) return IdentityMapResponse(resp_body, identity_map_input) diff --git a/uid2_client/publisher_client.py b/uid2_client/publisher_client.py index 80c4496..c9ee6ec 100644 --- a/uid2_client/publisher_client.py +++ b/uid2_client/publisher_client.py @@ -50,12 +50,12 @@ def generate_token(self, token_generate_input): req, nonce = make_v2_request(self._secret_key, dt.datetime.now(tz=timezone.utc), token_generate_input.get_as_json_string().encode()) resp = post(self._base_url, '/v2/token/generate', headers=auth_headers(self._auth_key), data=req) - resp_body = parse_v2_response(self._secret_key, resp.read(), nonce) + resp_body = parse_v2_response(self._secret_key, resp.text, nonce) return TokenGenerateResponse(resp_body) def refresh_token(self, current_identity): resp = post(self._base_url, '/v2/token/refresh', headers=auth_headers(self._auth_key), data=current_identity.get_refresh_token().encode()) - resp_bytes = base64_to_byte_array(resp.read()) + resp_bytes = base64_to_byte_array(resp.text) decrypted = _decrypt_gcm(resp_bytes, base64_to_byte_array(current_identity.get_refresh_response_key())) return TokenRefreshResponse(decrypted.decode(), dt.datetime.now(tz=timezone.utc)) diff --git a/uid2_client/refresh_keys_util.py b/uid2_client/refresh_keys_util.py index 791d89b..3e61897 100644 --- a/uid2_client/refresh_keys_util.py +++ b/uid2_client/refresh_keys_util.py @@ -38,7 +38,7 @@ def _fetch_keys(base_url, path, auth_key, secret_key): try: req, nonce = make_v2_request(secret_key, dt.datetime.now(tz=timezone.utc)) resp = post(base_url, path, headers=auth_headers(auth_key), data=req) - resp_body = json.loads(parse_v2_response(secret_key, resp.read(), nonce)).get('body') + resp_body = json.loads(parse_v2_response(secret_key, resp.text, nonce)).get('body') keys = _parse_keys_json(resp_body) return RefreshResponse.make_success(keys) except Exception as exc: diff --git a/uid2_client/request_response_util.py b/uid2_client/request_response_util.py index 0809102..c4741b7 100644 --- a/uid2_client/request_response_util.py +++ b/uid2_client/request_response_util.py @@ -1,7 +1,7 @@ import base64 from importlib.metadata import version import os -from urllib import request +import requests from uid2_client.encryption import _encrypt_gcm, _decrypt_gcm @@ -41,5 +41,4 @@ def parse_v2_response(secret_key, encrypted, nonce): def post(base_url, path, headers, data): - req = request.Request(_make_url(base_url, path), headers=headers, method='POST', data=data) - return request.urlopen(req) + return requests.post(_make_url(base_url, path), data=data, headers=headers)