From 2c35144ce2ead34b365bfa24aaec0f3a67bb5d54 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Fri, 6 Jan 2023 17:12:42 +0530 Subject: [PATCH 1/3] feat: add urllib3 to requirement --- json2xml/utils.py | 1 - requirements.in | 2 +- requirements.txt | 10 ++++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 requirements.txt diff --git a/json2xml/utils.py b/json2xml/utils.py index 0859fe27..7bff16b3 100644 --- a/json2xml/utils.py +++ b/json2xml/utils.py @@ -3,7 +3,6 @@ """Utils methods to convert XML data to dict from various sources""" import json -import requests class JSONReadError(Exception): diff --git a/requirements.in b/requirements.in index 27964c51..89b27cee 100644 --- a/requirements.in +++ b/requirements.in @@ -1,3 +1,3 @@ -requests>=2.20.0 defusedxml==0.7.1 +urllib3==1.26.13 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..83c88aca --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile +# +defusedxml==0.7.1 + # via -r requirements.in +urllib3==1.26.13 + # via -r requirements.in From bc24ec33cf24b30476ea62dd2d018359940728d2 Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Fri, 6 Jan 2023 17:30:15 +0530 Subject: [PATCH 2/3] feat: replace code to use urllib3 in place of requests --- json2xml/utils.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/json2xml/utils.py b/json2xml/utils.py index 7bff16b3..5deeabda 100644 --- a/json2xml/utils.py +++ b/json2xml/utils.py @@ -2,7 +2,7 @@ """Utils methods to convert XML data to dict from various sources""" import json - +import urllib3 class JSONReadError(Exception): @@ -42,11 +42,12 @@ def readfromurl(url: str, params: dict[str, str] | None = None) -> dict[str, str """ Loads json from an URL over the internets """ - # TODO: See if we can remove requests too from the deps too. Then, we will become - # zero deps. refernce link here: https://bit.ly/3gzICjU - response = requests.get(url, params=params) - if response.status_code == 200: - data = response.json() + # we need a PoolManager for connection pooling with urllib3. Also, params + # needs to be encoded too + http = urllib3.PoolManager() + response = http.request("GET", url, fields=params) + if response.status == 200: + data = json.loads(response.data.decode('utf-8')) return data raise URLReadError("URL is not returning correct response") From 309795c067281ad532c8ac874471ec554da0660f Mon Sep 17 00:00:00 2001 From: Vinit Kumar Date: Fri, 6 Jan 2023 17:32:21 +0530 Subject: [PATCH 3/3] fix: rename and fix the isort issue --- .github/workflows/lint.yml | 2 +- json2xml/utils.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 19366ec9..71513a62 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,4 +1,4 @@ -name: django CMS linters.yml +name: json2xml linters.yml on: [push, pull_request] diff --git a/json2xml/utils.py b/json2xml/utils.py index 5deeabda..d5109bdf 100644 --- a/json2xml/utils.py +++ b/json2xml/utils.py @@ -2,6 +2,7 @@ """Utils methods to convert XML data to dict from various sources""" import json + import urllib3