taers232c / GAMADV-XTD3

Command line tool to manage Google Workspace
703 stars 87 forks source link

Getting contacts from large contact groups fails with "ERROR: 503: serviceNotAvailable" #315

Closed egenethebest closed 1 year ago

egenethebest commented 1 year ago

Often when trying to print users's contacts in a large contact group GAM ends up erroring our with: ERROR: 503: serviceNotAvailable - The service is currently unavailable.

This causes many of my scripts that sync contactgroups to fail since it does not retry and just fails. Maybe it should back off like it does when you exceed a quota ?

Here is an example of this occuring:

$ gam user <username> print contacts selectcontactgroup <contact-group>
Getting all People Contacts for user@mydomain.com
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 32 seconds, Retry: 5/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 32 seconds, Retry: 5/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 32 seconds, Retry: 5/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 32 seconds, Retry: 5/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 32 seconds, Retry: 5/10
Temporary error: quotaExceeded - Quota exceeded for quota metric 'Critical read requests (Contact and Profile Reads)' and limit 'Critical read requests (Contact and Profile Reads) per minute per user' of service 'people.googleapis.com' for consumer 'project_number:0000000000000'., Backing off: 16 seconds, Retry: 4/10

ERROR: 503: serviceNotAvailable - The service is currently unavailable.

This specific contact group has about 1.5K contacts, however, I have seen this occur with as little as over 100 contacts.

GAM Version used:

$ gam version
GAMADV-XTD3 6.28.01 - https://github.com/taers232c/GAMADV-XTD3 - pyinstaller
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.11.0 64-bit final
Linux Debian 9 Stretch x86_64
Path: /home/egene/bin/gamadv-xtd3
Config File: /home/egene/.gam/gam.cfg, Section: DEFAULT, customer_id: my_customer, domain: 
taers232c commented 1 year ago

Send me a Meet/Zoom invitation

ross.scroggs @ gmail.com

taers232c commented 1 year ago

The problem is in the People API. There is no parameter specifying a contact group when listing contacts. You have to make a call asking for a list of members in a contact group and then get their details with an API call per contact.

taers232c commented 1 year ago

Get 6.28.04 and try: gam user print contacts filtercontactgroup

egenethebest commented 1 year ago

Thank you very much Ross for your hard work! filtercontactgroup works like a charm, I am now getting a lot less errors.

PS. the Google People API is terrible, the legacy contacts API was way better.