Errors using a list of integers (Python + Google Ads API)
I have a list of IDs that are integers. If I do print(data_clients["id"])
I get something like:
4323324234 2342342344 5464564565
Then I want to call an API (Google Ads) that uses those numbers as IDs (to know which data to retrieve). I have to do a loop (or something similar) to get the data from each ID.
I've tried this
for id in range(data_clients["id"]): query = (f''' WHATEVER ''') stream = ga_service.search_stream(customer_id = data_clients["id"], query=query) list_id = []
With this code I get the following error:
4323324234 has type int, but expected one of: bytes, unicode
And if I try to convert the int to Unicode or bytes (with chr or to_bytes), I get
int too big to convert
Maybe the solution is obvious, but I'm a Python/coding beginner, so I'm pretty confused.
Any ideas? Thanks!
Assuming data_clients["id"] is a list of customer IDs, this should work:
for cust_id in data_clients["id"]: query = (f''' WHATEVER ''') stream = ga_service.search_stream(customer_id=cust_id, query=query)It gives me the error 'int' object is not iterable for the line for cust_id in data_clients["id"]:. I guess it's the same problem I mentioned in one of my previous comments (the ID numbers inside data_clients["id"] are integers so they can't be in a loop).
If you're getting the error 'int' object is not iterable, then that means data_clients["id"] is a single integer. There aren't any integers "inside" of it. But yet when I asked you to show the output of print(type(data_clients["id"])), you said it printed "a list". I don't see how both of these things can be true. You must be wrong about one of them.
OK, maybe I used the wrong word (I'm a Python newbie and English is not my first language). print(type(data_clients["id"])) gave me an output me several items, one after another, in different lines. I referred to that as a list, but I wasn't talking about a Python list (I'm still not sure what is the correct Python term for that).
Anyway, here is more data, in case it helps. If I do print(data_clients) I get: {'descriptive_name': 'name1', 'id': 4323324234, 'status': 'ENABLED'} {'descriptive_name': 'name2', 'id': 2342342344, 'status': 'ENABLED'} {'descriptive_name': 'name3', 'id': 5464564565, 'status': 'ENABLED'} (each in a different line)
And if I do print(data_clients["id"]) I get what I mentioned in my original message (4323324234 2342342344 5464564565, each in a different line). I would like to use those numbers as the customer_id, to send 1 query for each of those customers (so 3 different queries for those 3 numbers in that example).