diff --git a/.travis.yml b/.travis.yml index 9886908..dc6c49d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ cache: pip: true matrix: include: - - python: "3.8" - env: NOXSESSION="tests-3.8" - - python: "3.8" + - python: "3.9" + env: NOXSESSION="tests-3.9" + - python: "3.9" env: NOXSESSION="lint" dist: xenial install: diff --git a/noxfile.py b/noxfile.py index 417bce2..a1ecd49 100644 --- a/noxfile.py +++ b/noxfile.py @@ -3,7 +3,7 @@ nox.options.sessions = ["tests", "lint", "build"] -python = ["3.8"] +python = ["3.9"] lint_dependencies = [ diff --git a/setup.py b/setup.py index 70fa689..9631c89 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,6 @@ packages=find_packages(), setup_requires=[], url="https://github.com/upwork/python-upwork", - version="2.0.1", + version="2.1.0", zip_safe=False, ) diff --git a/tests/test_client.py b/tests/test_client.py index c7a8e1d..6525694 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -103,6 +103,7 @@ def test_send_request(self, mocked_get, mocked_post, mocked_put, mocked_delete): } ) cl = client.Client(cfg) + cl.requests = requests assert cl.get("/test/uri", {}) == {"a": "b"} assert cl.post("/test/uri", {}) == {"a": "b"} assert cl.put("/test/uri", {}) == {"a": "b"} diff --git a/upwork/__init__.py b/upwork/__init__.py index 21ab8d4..88f2985 100644 --- a/upwork/__init__.py +++ b/upwork/__init__.py @@ -6,6 +6,6 @@ __author__ = """Maksym Novozhylov""" __email__ = "mnovozhilov@upwork.com" -__version__ = "2.0.1" +__version__ = "2.1.0" __all__ = ("Config", "Client", "routers") diff --git a/upwork/client.py b/upwork/client.py index de79787..f7ba8dc 100644 --- a/upwork/client.py +++ b/upwork/client.py @@ -13,6 +13,8 @@ import requests from . import upwork +from requests.adapters import HTTPAdapter +from requests.packages.urllib3.util.retry import Retry from requests_oauthlib import OAuth1 # type: ignore from urllib.parse import parse_qsl, urlencode @@ -36,6 +38,9 @@ class Client(object): def __init__(self, config): self.config = config + self.requests = requests.Session() + self.requests.mount('https://', HTTPAdapter(max_retries=Retry(total=0))) + def get_request_token(self): """Get request token""" oauth = OAuth1(self.config.consumer_key, self.config.consumer_secret) @@ -165,13 +170,13 @@ def send_request(self, uri, method="get", params={}): url = full_url(get_uri_with_format(uri, self.epoint), self.epoint) if method == "get": - r = requests.get(url, params=params, auth=oauth, verify=self.config.verify_ssl) + r = self.requests.get(url, params=params, auth=oauth, verify=self.config.verify_ssl) elif method == "put": headers = {"Content-type": "application/json"} - r = requests.put(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl) + r = self.requests.put(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl) elif method in {"post", "delete"}: headers = {"Content-type": "application/json"} - r = requests.post(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl) + r = self.requests.post(url, json=params, headers=headers, auth=oauth, verify=self.config.verify_ssl) else: raise ValueError( 'Do not know how to handle http method "{0}"'.format(method)