Skip to content
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### NEXT
## CHANGELOG

### NEXT RELEASE

* Remove 2015-vintage experimental "`all_updated`" action from trackers
* Correct references of `contact@easypost.com` to `support@easypost.com`

### v5.1.2 2021-06-10

Expand Down
25 changes: 13 additions & 12 deletions easypost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
__author__ = 'EasyPost <oss@easypost.com>'
__version__ = VERSION
version_info = VERSION_INFO
SUPPORT_EMAIL = 'support@easypost.com'


# use urlfetch as request_lib on google app engine, otherwise use requests
Expand All @@ -35,20 +36,20 @@
except ImportError:
raise ImportError('EasyPost requires an up to date requests library. '
'Update requests via "pip install -U requests" or '
'contact us at contact@easypost.com.')
'contact us at {}.'.format(SUPPORT_EMAIL))

try:
version = requests.__version__
major, minor, patch = [int(i) for i in version.split('.')]
except Exception:
raise ImportError('EasyPost requires an up to date requests library. '
'Update requests via "pip install -U requests" or contact '
'us at contact@easypost.com.')
'us at {}.'.format(SUPPORT_EMAIL))
else:
if major < 1:
raise ImportError('EasyPost requires an up to date requests library. Update '
'requests via "pip install -U requests" or contact us '
'at contact@easypost.com.')
'at {}.'.format(SUPPORT_EMAIL))

# config
api_key = None
Expand Down Expand Up @@ -276,7 +277,7 @@ def request_raw(self, method, url, params=None, apiKeyRequired=True):
raise Error(
'No API key provided. Set an API key via "easypost.api_key = \'APIKEY\'. '
'Your API keys can be found in your EasyPost dashboard, or you can email us '
'at contact@easypost.com for assistance.')
'at {} for assistance.'.format(SUPPORT_EMAIL))

abs_url = self.api_url(url)
params = self._objects_to_ids(params)
Expand Down Expand Up @@ -314,8 +315,8 @@ def request_raw(self, method, url, params=None, apiKeyRequired=True):
elif request_lib == 'requests':
http_body, http_status = self.requests_request(method, abs_url, headers, params)
else:
raise Error("Bug discovered: invalid request_lib: %s. "
"Please report to contact@easypost.com." % request_lib)
raise Error("Bug discovered: invalid request_lib: {}. "
"Please report to {}.".format(request_lib, SUPPORT_EMAIL))

return http_body, http_status, my_api_key

Expand All @@ -337,8 +338,8 @@ def requests_request(self, method, abs_url, headers, params):
elif method == 'post' or method == 'put':
data = self.encode(params)
else:
raise Error("Bug discovered: invalid request method: %s. "
"Please report to contact@easypost.com." % method)
raise Error("Bug discovered: invalid request method: {}. "
"Please report to {}.".format(method, SUPPORT_EMAIL))

try:
result = requests_session.request(
Expand All @@ -353,7 +354,7 @@ def requests_request(self, method, abs_url, headers, params):
http_status = result.status_code
except Exception as e:
raise Error("Unexpected error communicating with EasyPost. If this "
"problem persists please let us know at contact@easypost.com.",
"problem persists please let us know at {}.".format(SUPPORT_EMAIL),
original_exception=e)
return http_body, http_status

Expand All @@ -364,8 +365,8 @@ def urlfetch_request(self, method, abs_url, headers, params):
elif method == 'get' or method == 'delete':
abs_url = self.build_url(abs_url, params)
else:
raise Error("Bug discovered: invalid request method: %s. Please report "
"to contact@easypost.com." % method)
raise Error("Bug discovered: invalid request method: {}. Please report "
"to {}.".format(method, SUPPORT_EMAIL))

args['url'] = abs_url
args['method'] = method
Expand All @@ -377,7 +378,7 @@ def urlfetch_request(self, method, abs_url, headers, params):
result = urlfetch.fetch(**args)
except Exception as e:
raise Error("Unexpected error communicating with EasyPost. "
"If this problem persists, let us know at contact@easypost.com.",
"If this problem persists, let us know at {}.".format(SUPPORT_EMAIL),
original_exception=e)

return result.content, result.status_code
Expand Down