Skip to content

Commit ab9de38

Browse files
authored
Merge pull request #48 from smartystreets/eric/proxy-http-fix
Fix Http Proxy Issue
2 parents aa67ca5 + 97ed7eb commit ab9de38

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

examples/us_enrichment_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def run():
2727
# https://www.smartystreets.com/docs/cloud/licensing
2828
client = ClientBuilder(credentials).with_licenses(["us-property-data-principal-cloud"]).build_us_enrichment_api_client()
2929
# client = ClientBuilder(credentials).with_custom_header({'User-Agent': 'smartystreets ([email protected])', 'Content-Type': 'application/json'}).build_us_enrichment_api_client()
30-
# client = ClientBuilder(credentials).with_proxy('localhost:8080', 'user', 'password').build_us_street_api_client()
30+
# client = ClientBuilder(credentials).with_http_proxy('localhost:8080', 'user', 'password').build_us_street_api_client()
3131
# Uncomment the line above to try it with a proxy instead
3232

3333
smarty_key = "1682393594"

examples/us_street_single_address_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run():
2828
# https://www.smartystreets.com/docs/cloud/licensing
2929
client = ClientBuilder(credentials).with_licenses(["us-core-cloud"]).build_us_street_api_client()
3030
# client = ClientBuilder(credentials).with_custom_header({'User-Agent': 'smartystreets ([email protected])', 'Content-Type': 'application/json'}).build_us_street_api_client()
31-
# client = ClientBuilder(credentials).with_proxy('localhost:8080', 'user', 'password').build_us_street_api_client()
31+
# client = ClientBuilder(credentials).with_http_proxy('localhost:8080', 'user', 'password').build_us_street_api_client()
3232
# Uncomment the line above to try it with a proxy instead
3333

3434
# Documentation for input fields can be found at:

smartystreets_python_sdk/client_builder.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,28 @@ def with_base_url(self, base_url):
8484
self.url_prefix = base_url
8585
return self
8686

87-
def with_proxy(self, host, username=None, password=None):
87+
def with_http_proxy(self, host, username=None, password=None):
8888
"""
89-
Assigns a proxy through which to send all Lookups.
89+
Assigns a http proxy through which to send all Lookups.
9090
:param host: The proxy host including port, but not scheme. (example: localhost:8080)
9191
:param username: Username to authenticate with the proxy server
9292
:param password: Password to authenticate with the proxy server
9393
:return: Returns self to accommodate method chaining.
9494
"""
95-
self.proxy = smarty.Proxy(host, username, password)
95+
full_host = 'http://' + host
96+
self.proxy = smarty.Proxy(full_host, username, password)
97+
return self
98+
99+
def with_https_proxy(self, host, username=None, password=None):
100+
"""
101+
Assigns a https proxy through which to send all Lookups.
102+
:param host: The proxy host including port, but not scheme. (example: localhost:8080)
103+
:param username: Username to authenticate with the proxy server
104+
:param password: Password to authenticate with the proxy server
105+
:return: Returns self to accommodate method chaining.
106+
"""
107+
full_host = 'https://' + host
108+
self.proxy = smarty.Proxy(full_host, username, password)
96109
return self
97110

98111
def with_custom_header(self, custom_header):

smartystreets_python_sdk/requests_sender.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ def send(self, smarty_request):
2929
def build_proxies(self):
3030
if not self.proxy:
3131
return {}
32-
if not self.proxy.host:
32+
if (self.proxy.host == 'http://' or self.proxy.host =='https://'):
3333
raise smarty.exceptions.SmartyException('Proxy must have a valid host (including port)')
3434

35-
proxy_string = 'https://'
35+
proxy_string = self.proxy.host
3636

3737
if self.proxy.username:
3838
proxy_string += '{}:{}@'.format(self.proxy.username, self.proxy.password)
3939

40-
proxy_string += self.proxy.host
41-
42-
return {'https': proxy_string}
40+
if ('https://' in self.proxy.host):
41+
return {'https': proxy_string}
42+
else:
43+
return {'http': proxy_string, 'https': proxy_string}
4344

4445

4546
def build_request(smarty_request):

0 commit comments

Comments
 (0)