Wenn Sie über einen HTTP- oder HTTPS-Proxy eine Verbindung zur Google Ads API herstellen müssen, können Sie die Einstellung http_proxy in Ihrer Konfigurationsdatei, programmatisch oder über eine Umgebungsvariable konfigurieren. Die Einstellung http_proxy gilt für den zugrunde liegenden gRPC-Transportkanal, der von der Python-Clientbibliothek verwendet wird.
Mit google-ads.yaml konfigurieren
Geben Sie die http_proxy-Einstellung in der google-ads.yaml-Datei an:
# Optional proxy configuration used for API requests. If your proxy does not
# require authentication, specify only the host and port.
http_proxy: INSERT_PROXY_HERE
Sie können beispielsweise http://user:pass@localhost:8082 als Proxy angeben.
Programmatisch konfigurieren
Sie können die Proxyeinstellung auch programmatisch mit den Initialisierungsmethoden GoogleAdsClient (load_from_dict, load_from_env und load_from_string) konfigurieren, genau wie jede andere Konfigurationseinstellung:
from google.ads.googleads.client import GoogleAdsClient
config = {
# Include other required configuration settings here.
"http_proxy": "INSERT_PROXY_HERE",
}
googleads_client = GoogleAdsClient.load_from_dict(config)
Über Umgebungsvariablen konfigurieren
Wenn Sie einen Proxy mit der Methode load_from_env konfigurieren möchten, legen Sie die Umgebungsvariable GOOGLE_ADS_HTTP_PROXY fest:
export GOOGLE_ADS_HTTP_PROXY="http://user:pass@localhost:8082"