google-api-python-client: APIs that accept arrays as an input parameter blocked by client validation

Currently, when an API supports multiple parameters via an array, the API client throws an exception due to this logic:

https://github.com/googleapis/google-api-python-client/blob/ffea1a7fe9d381d23ab59048263c631cc2b45323/googleapiclient/_helpers.py#L155-L158

What is the purpose of this validation? It seems unnecessary as sending an HTTP request with multiple parameter values is valid against the HTTP spec and many APIs support this. See Campaign Manager v3.3 - campaigns.list() spec - Example is advertiserIds parameter.

Example valid HTTP call that returns the expected result: https://content.googleapis.com/dfareporting/v3.3/userprofiles/4478/placements?advertiserIds=1782317&advertiserIds=1782314&key=

However, due to the validation logic, if you make the same call via the CM API utility that utilizes this library to make the request, it will fail due to the validation logic mentioned above.

Single advertiserIds=9015669 does work. But when I make the method call as:

request = service.campaigns().list(profileId=profile_id,advertiserIds=[9015669,6487689])

ValueError: URL-encoded content contains a repeated value:advertiserIds -> 9015669, 6487689

This was brought to our attention by a client who couldn’t understand why Google’s API client doesn’t support Google’s API spec. I traced through the issue to this line. Commenting out the exception logic resolves the issue and returns the desired results from the API.

Please remove this validation as it doesn’t seem to solve any issues and actually prevents many valid API calls from being executed.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (10 by maintainers)

Most upvoted comments

Sorry, this is such a weird non-intuitive bug that just derailed me for a while. At this point, the chances of any new engineer using the gmail API using the labels feature is high (def what I touched first since it’s easy to grok) and will almost immediately hit this strange bug the moment they try to pull more than 10 emails down.

It is SO confusing. We should consider reopening this one.