2016-10-12 32 views
2

沒有其他類似名稱的問題已經解決了我的問題。HTTP錯誤400錯誤的請求(其他類似的問題沒有幫助我)

爲什麼我會收到此錯誤?我從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/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() 

Here is where I go the code from

我收到此錯誤:

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"> 
+0

這真的是你的鑰匙嗎? –

回答

1

我試圖訪問bad URL是說,原因是 「keyExpired」。同時,把這裏的代碼包括下列文件:

訪問的谷歌API控制檯http://code.google.com/apis/console到 獲取自己的應用程序的API密鑰。

嘗試這樣做,因爲它說。祝你好運!