提问人:anonymous developer 提问时间:6/25/2023 最后编辑:anonymous developer 更新时间:6/27/2023 访问量:130
为什么我从 python 调用的 google 自定义搜索 API 不起作用?
Why is my google custom search API call from python not working?
问:
当我运行以下代码时,我收到错误响应(请参阅第二个代码段)。我已经检查并确保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 返回中换行(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^文件 “/usr/local/lib/python3.11/site-packages/googleapiclient/http.py”, 第 938 行,在执行中引发 HttpError(resp, content, uri=self.uri) <请求 https://customsearch.googleapis.com/customsearch/v1?q=%22Software%22&cx=<SEARCH_ENGINE_ID>&num=100&key=<API_KEY>&alt=json 时出现 HttpError 400 返回“请求包含无效参数”。详: “[{'message': '请求包含无效参数。', 'domain': 'global', 'reason': 'badRequest'}]“>
答: 暂无答案
评论