Skip to content

Commit

Permalink
Use requests session
Browse files Browse the repository at this point in the history
  • Loading branch information
DorianGray committed Dec 20, 2016
1 parent d0a7ea0 commit 8dd3871
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions easypost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import types
import re
from six.moves.urllib.parse import urlencode, quote_plus, urlparse

from .version import VERSION


# use urlfetch as request_lib on google app engine, otherwise use requests
request_lib = None
try:
Expand All @@ -18,6 +18,7 @@
try:
import requests
request_lib = 'requests'
requests_session = requests.Session()
except ImportError:
raise ImportError('EasyPost requires an up to date requests library. '
'Update requests via "pip install -U requests" or '
Expand Down Expand Up @@ -308,7 +309,14 @@ def requests_request(self, method, abs_url, headers, params):
"Please report to [email protected]." % method)

try:
result = requests.request(method, abs_url, headers=headers, data=data, timeout=60, verify=True)
result = requests_session.request(
method,
abs_url,
headers=headers,
data=data,
timeout=60,
verify=True,
)
http_body = result.text
http_status = result.status_code
except Exception as e:
Expand Down

0 comments on commit 8dd3871

Please sign in to comment.