Jay
Jay

Reputation: 427

503 service is unavailable in Analytics Reporting API V4

Sample Call: https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json

Sample Error:

googleapiclient.errors.HttpError: <HttpError 503 when requesting https://analyticsreporting.googleapis.com/v4/reports:batchGet?alt=json returned "The service is currently unavailable.". Details: "The service is currently unavailable.">

Calling it once an hour instead of backoff fails every time. Then, after a day or two, it intermittently succeeds. Only one account has a problem. The rest is fine.

code:

        query = {
            "reportRequests": [
                {
                    "viewId": str(view_id),
                    "dateRanges": [
                        {
                            "startDate": "2022-11-29",
                            "endDate": "2022-11-29",
                        }
                    ],
                    "metrics": [{"expression": "ga:users"}, {"expression": "ga:newUsers"}, {"expression": "ga:transactions"}],
                    "dimensions": [{"name": "ga:source"}, {"name": "ga:medium"}, {"name": "ga:campaign"}, {"name": "ga:adContent"},
                    "pageSize": 100_000,
                }
            ]
        }

        return service.reports().batchGet(body=query).execute()

Thanks for your help.

Upvotes: 1

Views: 1271

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116948

First off 500 errors are something is wrong on Googles end. There is nothing you can do to fix it. Its often caused by the server being over loaded, and your script timing out.

A tip would be to never run on the hour, everyone that has a cron job set up has it set to run on the hour and your going to be completing for server processing with everyone else.

I cant see anything wrong with the code you have.

PRO tip. the google apis python client library has back off built in. So if your seeing a 500 error the library has already retried the call about ten times before you are even seeing the error.

Upvotes: 2

Related Questions