python 脚本中的 ListRecommendationsRequest 构造函数错误

ListRecommendationsRequest constructor error in python script

我正在尝试使用 python3.7 脚本准备 VM 大小调整建议报告 我的代码如下:

导入日期时间

import logging
from google.cloud import bigquery
from google.cloud import recommender
from google.cloud.exceptions import NotFound
from googleapiclient import discovery

def main(event, context):
 client = recommender.RecommenderClient()
 recommender_type = "google.compute.instance.MachineTypeRecommender"
 projects=list_projects() #This gives list of projects
 # I hard-code the zones below:
 zones = ["us-east1-b","us-east1-c","us-east1-d","us-east4-c","us-east4-b","us-east4-a"
        ,"us-central1-c","us-central1-a","us-central1-f","us-central1-b"
        ,"us-west1-b","us-west1-c","us-west1-a"]

 for zone in zones:
            parent = client.recommender_path("my-project", zone, recommender_type)
            for element in client.list_recommendations(parent): #In this line I am getting this error and these are logs

****Parent****   projects/my-project/locations/us-east1-b/recommenders/google.compute.instance.MachineTypeRecommender
Traceback (most recent call last):
  File "main.py", line 187, in main
    x=list(client.list_recommendations(parent))
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/google/cloud/recommender_v1/services/recommender/client.py", line 734, in list_recommendations
    request = recommender_service.ListRecommendationsRequest(request)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/proto/message.py", line 441, in __init__
    raise TypeError(
TypeError: Invalid constructor input for ListRecommendationsRequest: 'projects/my-project/locations/us-east1-b/recommenders/google.compute.instance.MachineTypeRecommender'

During handling of the above exception, another exception occurred:

projects/my-project/locations/us-east1-b/recommenders/google.compute.instance.MachineTypeRecommender 是传递给 list_recommendations 函数的参数。当我得到这个时,我不确定构造函数中有什么问题:ListRecommendationsRequest

的构造函数输入无效

我是新手 google api。有人可以帮忙吗?谢谢

我检查了我这边的代码,调用该方法时似乎是语法错误。根据 library documentation 第一个参数应该是 请求对象 None 并且必须传递父参数按名字。如下更改行我没有错误:

client.list_recommendations(parent=parent)