当我运行以下代码时,我收到错误响应(请参阅第二个片段)。我已检查并确保 GOOGLE_SEARCH_KEY 和 SEARCH_ENGINE_ID 有效,并且帐单设置正确。我已从错误消息中删除敏感数据并放入占位符。可能是什么问题?预先感谢。
from googleapiclient.discovery import build
try:
api_key = GOOGLE_SEARCH_KEY
search_engine_id = SEARCH_ENGINE_ID
query = "test"
num_results = 100
service = build("customsearch", "v1",
developerKey=api_key)
response = service.cse().list(
q=query,
cx=search_engine_id,
num=num_results
).execute()
except Exception as e:
print(e)
文件“x.py”,第 34 行,在搜索 ).execute() ^^^^^^^^^ 文件 “/usr/local/lib/python3.11/site-packages/googleapiclient/_helpers.py”, 第130行,在positional_wrapper中返回wrapped(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ 文件 “/usr/local/lib/python3.11/site-packages/googleapiclient/http.py”, 第 938 行,在执行中 raise HttpError(resp, content, uri=self.uri)
https://customsearch.googleapis.com/customsearch/v1?q=%22Software%22&cx= &num=100&key= &alt=json 返回“请求包含无效参数。”。细节: "[{'message': '请求包含无效参数。', 'domain': 'global', 'reason': 'badRequest'}]">
结果数 = 100 到 结果数 = 10