From 884fb79794217a90452b0ca6b0c16db94d54c96e Mon Sep 17 00:00:00 2001 From: Jan Range Date: Thu, 8 Feb 2024 19:08:21 +0100 Subject: [PATCH] replace requests exceptions and import `urllib3` --- src/pyDataverse/__init__.py | 3 ++- src/pyDataverse/api.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/pyDataverse/__init__.py b/src/pyDataverse/__init__.py index 965617b..6c5fe28 100644 --- a/src/pyDataverse/__init__.py +++ b/src/pyDataverse/__init__.py @@ -4,9 +4,10 @@ Licensed under the MIT License. """ + from __future__ import absolute_import -from requests.packages import urllib3 +import urllib3 urllib3.disable_warnings() # noqa diff --git a/src/pyDataverse/api.py b/src/pyDataverse/api.py index 4e6205e..14c4826 100644 --- a/src/pyDataverse/api.py +++ b/src/pyDataverse/api.py @@ -5,7 +5,7 @@ import subprocess as sp from urllib.parse import urljoin -from requests import ConnectionError, Response, delete, get, post, put +from httpx import ConnectError, Response from pyDataverse.exceptions import ( ApiAuthorizationError, @@ -139,8 +139,8 @@ def get_request(self, url, params=None, auth=False): ) ) return resp - except ConnectionError: - raise ConnectionError( + except ConnectError: + raise ConnectError( "ERROR: GET - Could not establish connection to api {0}.".format(url) ) @@ -184,8 +184,8 @@ def post_request(self, url, data=None, auth=False, params=None, files=None): ) ) return resp - except ConnectionError: - raise ConnectionError( + except ConnectError: + raise ConnectError( "ERROR: POST - Could not establish connection to API: {0}".format(url) ) @@ -225,8 +225,8 @@ def put_request(self, url, data=None, auth=False, params=None): ) ) return resp - except ConnectionError: - raise ConnectionError( + except ConnectError: + raise ConnectError( "ERROR: PUT - Could not establish connection to api '{0}'.".format(url) ) @@ -256,8 +256,8 @@ def delete_request(self, url, auth=False, params=None): try: return httpx.delete(url, params=params) - except ConnectionError: - raise ConnectionError( + except ConnectError: + raise ConnectError( "ERROR: DELETE could not establish connection to api {}.".format(url) )