Skip to content

Commit ddd672a

Browse files
committed
Added HTTP proxy support
1 parent 2db8a34 commit ddd672a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

ox3apiclient/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
4848
authorization_url=AUTHORIZATION_URL,
4949
api_path=API_PATH,
5050
email=None,
51-
password=None):
51+
password=None,
52+
http_proxy=None):
5253
"""
5354
5455
domain -- Your UI domain. The API is accessed off this domain.
@@ -62,7 +63,9 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
6263
access_token -- Only override for debugging.
6364
authorization_url -- Only override for debugging.
6465
api_path -- Only override for debugging.
66+
http_proxy -- Optional proxy to send HTTP requests through.
6567
"""
68+
6669
self.domain = domain
6770
self.realm = realm
6871
self.consumer_key = consumer_key
@@ -88,6 +91,10 @@ def __init__(self, domain, realm, consumer_key, consumer_secret,
8891
self._cookie_jar = cookielib.LWPCookieJar()
8992
opener = \
9093
urllib2.build_opener(urllib2.HTTPCookieProcessor(self._cookie_jar))
94+
# Add an HTTP proxy if necessary:
95+
if http_proxy:
96+
proxy = urllib2.ProxyHandler({'http': http_proxy})
97+
opener.add_handler(proxy)
9198

9299
urllib2.install_opener(opener)
93100

0 commit comments

Comments
 (0)