google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

'int' object is not iterable when making dfareporting call

Open aponbas opened this issue 2 years ago • 1 comments

We encounter the following error: request = service.placements().list(profileId=profileId)\n File "/usr/local/airflow/.local/lib/python3.7/site-packages/googleapiclient/discovery.py", line 980, in method\n for pvalue in pvalues:\nTypeError: 'int' object is not iterable", "timestamp": "2023-06-22T07:33:52.779813Z", "level": "ERROR"

Environment details

  • Python version: 3.7
  • google-api-python-client version: 1.12.8

Steps to reproduce

  1. call to service.placements().list(profileId=profileId)

Code example

from apiclient import discovery
import google.oauth2.service_account

profileId = #id here


def get_service():
    key_path = "credentials.json"
    scopes = (
        "https://www.googleapis.com/auth/datastore",
        "https://www.googleapis.com/auth/cloud-platform",
        "https://www.googleapis.com/auth/analytics",
        "https://www.googleapis.com/auth/dfatrafficking",
    )

    credentials = (
        google.oauth2.service_account.Credentials.from_service_account_file(
            key_path, scopes=scopes)
    )

    api_name = "dfareporting"
    api_version = "v4"
    service = discovery.build(serviceName=api_name,
                              version=api_version,
                              credentials=credentials,
                              developerKey=None)

    return service


def get_placements():
    service = get_service()
    request = service.placements().list(profileId=profileId)
    response = request.execute()
    print(response)


get_placements()

Stack trace

request = service.placements().list(profileId=profileId)\n File \"/usr/local/airflow/.local/lib/python3.7/site-packages/googleapiclient/discovery.py\", line 980, in method\n for pvalue in pvalues:\nTypeError: 'int' object is not iterable", "timestamp": "2023-06-22T07:33:52.779813Z", "level": "ERROR" 

We've investigated this and concluded that the error is in the library that you provide. More specifically, in the following piece of code (line 1065):

    for name, regex in parameters.pattern_params.items():
        if name in kwargs:
            if isinstance(kwargs[name], str):
                pvalues = [kwargs[name]]
            else:
                pvalues = kwargs[name]
            for pvalue in pvalues:
                if re.match(regex, pvalue) is None:
                    raise TypeError(
                        'Parameter "%s" value "%s" does not match the pattern "%s"'
                        % (name, pvalue, regex)
                    )

As we did not change anything on our side, we are wondering if something changed on your side. We noted this started happening the day after you released version 2.90.0, but since we use 1.12.8 we think it shouldn't be related. Either way, it would be an amazing coincidence. We've investigated that the first version that this calls works at is 2.51.0. I hope you can help us with this. We are looking forward to your answer.

aponbas avatar Jun 27 '23 11:06 aponbas

https://github.com/googleapis/google-api-python-client/issues/2185#issuecomment-1629923156

Try this

ken999999999999999 avatar Jul 11 '23 01:07 ken999999999999999