Skip to content

Commit 7d900ac

Browse files
committed
Change from urllib to requests
1 parent 8506445 commit 7d900ac

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ classifiers = [
2020
]
2121
requires-python = ">=3.8"
2222
dependencies = [
23+
"requests",
2324
"pycryptodome",
2425
"bitarray"
2526
]

uid2_client/identity_map_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ def generate_identity_map(self, identity_map_input):
3636
req, nonce = make_v2_request(self._client_secret, dt.datetime.now(tz=timezone.utc),
3737
identity_map_input.get_identity_map_input_as_json_string().encode())
3838
resp = post(self._base_url, '/v2/identity/map', headers=auth_headers(self._api_key), data=req)
39-
resp_body = parse_v2_response(self._client_secret, resp.read(), nonce)
39+
resp_body = parse_v2_response(self._client_secret, resp.text, nonce)
4040
return IdentityMapResponse(resp_body, identity_map_input)

uid2_client/publisher_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def generate_token(self, token_generate_input):
5050
req, nonce = make_v2_request(self._secret_key, dt.datetime.now(tz=timezone.utc),
5151
token_generate_input.get_as_json_string().encode())
5252
resp = post(self._base_url, '/v2/token/generate', headers=auth_headers(self._auth_key), data=req)
53-
resp_body = parse_v2_response(self._secret_key, resp.read(), nonce)
53+
resp_body = parse_v2_response(self._secret_key, resp.text, nonce)
5454
return TokenGenerateResponse(resp_body)
5555

5656
def refresh_token(self, current_identity):
5757
resp = post(self._base_url, '/v2/token/refresh', headers=auth_headers(self._auth_key),
5858
data=current_identity.get_refresh_token().encode())
59-
resp_bytes = base64_to_byte_array(resp.read())
59+
resp_bytes = base64_to_byte_array(resp.text)
6060
decrypted = _decrypt_gcm(resp_bytes, base64_to_byte_array(current_identity.get_refresh_response_key()))
6161
return TokenRefreshResponse(decrypted.decode(), dt.datetime.now(tz=timezone.utc))

uid2_client/refresh_keys_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _fetch_keys(base_url, path, auth_key, secret_key):
3838
try:
3939
req, nonce = make_v2_request(secret_key, dt.datetime.now(tz=timezone.utc))
4040
resp = post(base_url, path, headers=auth_headers(auth_key), data=req)
41-
resp_body = json.loads(parse_v2_response(secret_key, resp.read(), nonce)).get('body')
41+
resp_body = json.loads(parse_v2_response(secret_key, resp.text, nonce)).get('body')
4242
keys = _parse_keys_json(resp_body)
4343
return RefreshResponse.make_success(keys)
4444
except Exception as exc:

uid2_client/request_response_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import base64
22
from importlib.metadata import version
33
import os
4-
from urllib import request
4+
import requests
55

66
from uid2_client.encryption import _encrypt_gcm, _decrypt_gcm
77

@@ -41,5 +41,4 @@ def parse_v2_response(secret_key, encrypted, nonce):
4141

4242

4343
def post(base_url, path, headers, data):
44-
req = request.Request(_make_url(base_url, path), headers=headers, method='POST', data=data)
45-
return request.urlopen(req)
44+
return requests.post(_make_url(base_url, path), data=data, headers=headers)

0 commit comments

Comments
 (0)