Python HTTP错误400错误请求(其他类似问题对我没有帮助)
其他类似的问题都没有解决我的问题 为什么我会犯这个错误?我从google的github复制并粘贴了这个示例代码Python HTTP错误400错误请求(其他类似问题对我没有帮助),python,google-api,google-api-python-client,Python,Google Api,Google Api Python Client,其他类似的问题都没有解决我的问题 为什么我会犯这个错误?我从google的github复制并粘贴了这个示例代码 import pprint from googleapiclient.discovery import build def main(): # Build a service object for interacting with the API. Visit # the Google APIs Console <http://code.google.com/apis
import pprint
from googleapiclient.discovery import build
def main():
# Build a service object for interacting with the API. Visit
# the Google APIs Console <http://code.google.com/apis/console>
# to get an API key for your own application.
service = build("customsearch", "v1",
developerKey="AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0")
res = service.cse().list(
q='lectures',
cx='017576662512468239146:omuauf_lfve',
).execute()
pprint.pprint(res)
if __name__ == '__main__':
main()
导入pprint
从GoogleAppClient.discovery导入生成
def main():
#构建用于与API交互的服务对象。参观
#谷歌API控制台
#为您自己的应用程序获取API密钥。
服务=构建(“自定义搜索”,“v1”,
developerKey=“AIzaSyDRRpR3GS1F1\u jKNNM9HCNd2wJQyPG3oN0”)
res=service.cse().list(
问:"讲座",,
cx='017576662512468239146:omuauf_lfve',
).execute()
pprint.pprint(res)
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
main()
我得到这个错误:
Traceback (most recent call last):
File "testpython", line 17, in <module>
main()
File "testpython", line 12, in main
cx='017576662512468239146:omuauf_lfve',
File "/home/mddrill/.local/lib/python2.7/site-packages/oauth2client/util.py", line 137, in positional_wrapper
return wrapped(*args, **kwargs)
File "/home/mddrill/.local/lib/python2.7/site-packages/googleapiclient/http.py", line 838, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://www.googleapis.com/customsearch/v1?q=lectures&alt=json&cx=017576662512468239146%3Aomuauf_lfve&key=AIzaSyDRRpR3GS1F1_jKNNM9HCNd2wJQyPG3oN0 returned "Bad Request">
回溯(最近一次呼叫最后一次):
文件“testpython”,第17行,在
main()
文件“testpython”,第12行,在main中
cx='017576662512468239146:omuauf_lfve',
文件“/home/mddrill/.local/lib/python2.7/site packages/oauth2client/util.py”,第137行,在位置包装中
已包装退货(*args,**kwargs)
文件“/home/mddrill/.local/lib/python2.7/site packages/googleapiclient/http.py”,执行中第838行
raise HttpError(resp,content,uri=self.uri)
GoogleAppClient.errors.HttpError:
我试图访问它,它说原因是“keyExpired”。此外,您在此处输入的代码还包括以下文档:
访问GoogleAPI控制台查看
为您自己的应用程序获取API密钥
试着照上面说的做。祝你好运 那真的是你的钥匙吗?