google-ads-python icon indicating copy to clipboard operation
google-ads-python copied to clipboard

Error with GenerateKeywordHistoricalMetricsRequest

Open KrishnaM313 opened this issue 1 year ago • 1 comments

I am following the code given here https://developers.google.com/google-ads/api/samples/generate-historical-metrics#python to get historical metrics for certain keywords. However, I am getting an error when I try to set keywords, with the line request.keywords = ["mars cruise", "cheap cruise", "jupiter cruise"] used in the example.

AttributeError: Assignment not allowed to message, map, or repeated field "keywords" in protocol message object.

When I comment out the line in question, these are my logs: https://pastebin.com/aqEN4xY6

How do I resolve this?

KrishnaM313 avatar May 28 '24 22:05 KrishnaM313

it should be

request.keywords.extend('mars') request.keywords.extend("cheap cruise') request.keywords.extend("jupiter cruise")

MaxMorgenbesser avatar Jun 18 '24 15:06 MaxMorgenbesser

@KrishnaM313 thanks for the question.

My guess is that you have use_proto_plus set to False. When that's true, this type of assignment isn't possible. If you set it to True, then the example should execute without any changes.

If you want to continue with use_proto_plus set to False, then you can assign these values as such:

request.keywords.extend(["mars cruise", "cheap cruise", "jupiter cruise"])

BenRKarl avatar Aug 07 '24 14:08 BenRKarl