Implementing proxy with authentication

A previous solution to a similar issue addresses the known issue (no proxy support)

For my client, they require authentication via proxy as well and the above topic will not resolve this.

Refer to documentation as at time of writing here: https://developer.mypurecloud.com/api/rest/client-libraries/python/

Connect to a Proxy Server
If connecting to a proxy server, set the the address of your proxy server as follows:
PureCloudPlatformClientV2.configuration.proxy = 'YOUR_PROXY_URL'

If proxy is provided in standard format such as http://user:pass@proxy:port then the following replacement in rest.py may assist. It is what I have done to solve my issue.

import re
....
# https pool manager
if proxy:
	proxy_parts=re.search('^([^\/]+\/\/)(?:(.*)@)?(.*)',proxy)
	proxy_url=proxy_parts.group(1)+proxy_parts.group(3)
	auth_part=proxy_parts.group(2)
	
	if auth_part != None:         
		proxy_headers = urllib3.util.make_headers(proxy_basic_auth=auth_part)
	else:
		proxy_headers=None
	
	self.pool_manager = urllib3.ProxyManager(proxy_url,
		num_pools=pools_size,
		cert_reqs=cert_reqs,
		ca_certs=ca_certs,
		cert_file=cert_file,
		key_file=key_file,
		proxy_headers=proxy_headers
	)
else:
	self.pool_manager = urllib3.PoolManager(
		num_pools=pools_size,
		cert_reqs=cert_reqs,
		ca_certs=ca_certs,
		cert_file=cert_file,
		key_file=key_file
	)

The important parts here are to ensure proxy_url is just a url with no user:pass component and to specify a valid proxy_headers parameter for ProxyManager to use.

Thanks for the info and sample code. I've created API-4992 to add this to the SDK.

I note the code is similar to the kubernetes implementation which also doesn't seem to accommodate proxy with authentication. That makes me wonder if our client configuration is unusual. Nevertheless the library supports password authentication with proxy so it seems to me to be worth adding support for it.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.