Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

ET_Client() PROXY AUTHENTICATION #118

Open
tgtimoteo opened this issue Feb 3, 2020 · 1 comment
Open

ET_Client() PROXY AUTHENTICATION #118

tgtimoteo opened this issue Feb 3, 2020 · 1 comment
Labels

Comments

@tgtimoteo
Copy link

I'm trying to instanciate the ET_Client and get the 407 error... it's proxy authenticatio

How do I configure this class to read my proxies authentication?

@tgtimoteo tgtimoteo added the bug label Feb 3, 2020
@Gexar
Copy link

Gexar commented Jun 29, 2021

I am behind a corporate firewall, which means that my proxy needs login and password and here is how I did it (replace clientid, clientsecret, id, login, password and host with your values):

import os, ET_Client

login = "YOUR DATA GOES HERE"
password = "YOUR DATA GOES HERE"
proxy_host = "YOUR DATA GOES HERE"
clientid = "YOUR DATA GOES HERE"
clientsecret = "YOUR DATA GOES HERE"
authurl = "YOUR DATA GOES HERE"

proxy = f'http://{login}:{password}@{proxy_host}:8080'

os.environ['http_proxy'] = proxy 
os.environ['HTTP_PROXY'] = proxy
os.environ['https_proxy'] = proxy
os.environ['HTTPS_PROXY'] = proxy

print("Trying to log in...")
stubObj = ET_Client.ET_Client(False, False,
                             params={'clientid': clientid,
                                     "clientsecret":clientsecret,
                                     "useOAuth2Authentication":"True",
                                     "authenticationurl":authurl})
print("Login: DONE!")

proxy_settings = dict(http=proxy, https=proxy)
stubObj.soap_client.set_options(proxy=proxy_settings)

print('>>> Get all of the DataExtensions in an Account')
de = ET_Client.ET_DataExtension()
print('>>> Get all of the DataExtensions in an Account: DONE!')
de.auth_stub = stubObj
de.props = ["CustomerKey", "Name"]

print('>>> Fetching extensions\' data')
getResponse = de.get()
print(f'>>> Fetching extensions\' data: DONE!')
print(f'Retrieve Status: {getResponse.status}')
print(f'Code: {getResponse.code}')
print(f'Message: {getResponse.message}')
print(f'MoreResults: {getResponse.more_results}')
print(f'RequestID: {getResponse.request_id}')
print(f'Results Length: {len(getResponse.results)}')

Update: for the underlying soap client to use your proxy settings you need to specify them in the build_soap_client() method defined in FuelSDK/client.py at line 245. This is how I do it:
1)Add line

proxy_settings = dict(http=os.environ["HTTP_PROXY"], https=os.environ["HTTPS_PROXY"])

2)replace

self.soap_client = suds.client.Client(self.wsdl_file_url, faults=False, cachingpolicy=1)

with

self.soap_client = suds.client.Client(self.wsdl_file_url, faults=False, cachingpolicy=1, proxy=proxy_settings)

Edit: added new info, the update

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants