googleapis/python-analytics-data

Proxy Configuration for Google Analytics Data API 4

rezahabibi96 opened this issue · 3 comments

I need to config url proxy for GA4 Client Library to pass from http proxy server to run on a corporate machine.
Unfortunately there is no any rich documentation for it on their web (or maybe it is me which could not find them).

Google Analytic Data API (GA4)

I have tried to setup http_proxy or grpc_proxy by using:
os.environ['http_proxy'] = 'http://host:port'
os.environ['grpc_proxy'] = 'http://host:port'
But none of them worked.

Here are the snippet code:

if proxy:
    os.environ['http_proxy'] = 'http://some-proxy'
    os.environ['grpc_proxy'] = 'http://some-proxy'
        
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = config['service_account']        
property_id = config['property_id']

client = BetaAnalyticsDataClient()
request = RunReportRequest(
                        property=f"properties/{property_id}",
                        dimensions=[Dimension(name=dim) for dim in SCHEMA.topic_dims],
                        metrics=[Metric(name=met) for met in SCHEMA.topic_metr],
                        date_ranges=[DateRange(start_date=config['start_date'],
                                               end_date=config['end_date'])])
response = client.run_report(request)

I do not know how to use proxy configuration for GA4 client library.

Is GA4 API support for proxy configuration and how we should configure it to work properly?

Thank you.

Hi @rezahabibi96,

The only requirement is that you set the environment variable HTTP_PROXY or HTTPS_PROXY (or the lowercase versions thereof) as documented here.

As a next step, please could you try temporarily setting the following environment variables which enable debug information and run the code again?

 export GRPC_TRACE=http
 export GRPC_VERBOSITY=debug

Please do not share the output here after running the code as there may be sensitive information in the output. Please share only relevant error messages that you see.

I'm going to close this issue due to inactivity but please feel free to re-open it with more information.

Здравствуйте.
Я добавил "https_proxy" переменную окружения Windows в раздел "системные переменные" и данная библиотека у меня заработала. Спасибо большое!
image