Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ examples/upwork
upwork/__init__.py.back
python_upwork.egg-info
reference-docs
_gh-pages
_gh-pages
.idea
5 changes: 5 additions & 0 deletions upwork/ca_certs_locater.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# openssl installed using `brew install openssl`
OSX_PATH = '/usr/local/etc/openssl/cert.pem'

CUSTOM_SSL_CERT_PATH = os.getenv('UPWORK_SSL_CERT', '')


def get():
"""Return a path to a certificate authority file.
Expand All @@ -18,6 +20,9 @@ def get():
if os.path.exists(OSX_PATH):
return OSX_PATH

if CUSTOM_SSL_CERT_PATH and os.path.exists(CUSTOM_SSL_CERT_PATH):
return CUSTOM_SSL_CERT_PATH

# Fall back to the httplib2 default behavior by raising an
# ImportError if we have not found the file.
raise ImportError()
33 changes: 19 additions & 14 deletions upwork/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,19 @@

from urllib3 import Retry

from upwork import ca_certs_locater
from upwork.oauth import OAuth
from upwork.http import raise_http_error
from upwork.utils import decimal_default
from upwork.exceptions import IncorrectJsonResponseError


__all__ = ["Client"]


logger = logging.getLogger('python-upwork')

if os.environ.get("PYTHON_UPWORK_DEBUG", False):
if os.environ.get("PYTHON_UPWORK_DEBUG_FILE", False):
fh = logging.FileHandler(filename=os.environ["PYTHON_UPWORK_DEBUG_FILE"]
)
)
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
else:
Expand Down Expand Up @@ -92,13 +89,17 @@ class Client(object):

:timeout: (optional, default ``8 secs``)
Socket operations timeout.

:poolmanager: (optional, default ``None``)
http connection pool manager
from :py:mod:`urllib3.poolmanager`
"""

def __init__(self, public_key, secret_key,
oauth_access_token=None, oauth_access_token_secret=None,
fmt='json', finreport=True, hr=True, messages=True,
offers=True, provider=True, task=True, team=True,
timereport=True, job=True, timeout=8):
timereport=True, job=True, timeout=8, poolmanager=None):

self.public_key = public_key
self.secret_key = secret_key
Expand All @@ -114,17 +115,20 @@ def __init__(self, public_key, secret_key,
# """
# The warning will appear only in logs
logging.captureWarnings(True)
self.http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=ca_certs_locater.get(),
timeout=urllib3.Timeout(connect=0.5, read=float(timeout)),
retries=False
)
if poolmanager is None:
from upwork import ca_certs_locater
poolmanager = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=ca_certs_locater.get(),
timeout=urllib3.Timeout(connect=0.5, read=float(timeout)),
retries=False
)
self.http = poolmanager

self.oauth_access_token = oauth_access_token
self.oauth_access_token_secret = oauth_access_token_secret

#Namespaces
# Namespaces
self.auth = OAuth(self)

if finreport:
Expand Down Expand Up @@ -168,7 +172,7 @@ def __init__(self, public_key, secret_key,
from upwork.routers.job import Job
self.job = Job(self)

#Shortcuts for HTTP methods
# Shortcuts for HTTP methods
def get(self, url, data=None):
return self.read(url, data, method='GET', fmt=self.fmt)

Expand Down Expand Up @@ -231,7 +235,7 @@ def urlopen(self, url, data=None, method='GET', headers=None):
return self.http.urlopen(
method, url, body=post_data,
headers={'Content-Type':
'application/x-www-form-urlencoded;charset=UTF-8'})
'application/x-www-form-urlencoded;charset=UTF-8'})
elif method in ('PUT', 'DELETE'):
url = '{0}?{1}'.format(url, post_data)
headers['Content-Type'] = 'application/json'
Expand Down Expand Up @@ -307,4 +311,5 @@ def read(self, url, data=None, method='GET', fmt='json'):

if __name__ == "__main__":
import doctest

doctest.testmod()