前提・実現したいこと
Pythonで、GoogleのAPIであるCustom Search Site Restricted JSON APIを利用するスクリプトを作成したいと考えています。しかし、このAPIには1日のクエリ上限が存在しないのにも関わらず、何らかの上限に引っかかりエラーが返ってきてしまいます。引っかかっている上限の内容、および改善方法などを指摘して頂けると助かります。
発生している問題・エラーメッセージ
"code": 403, "message": "Request throttled due to daily limit being reached.", "errors": [ { "message": "Request throttled due to daily limit being reached.", "domain": "usageLimits", "reason": "dailyLimitExceeded" } ], "status": "RESOURCE_EXHAUSTED"
該当のソースコード
python3
1# -*- coding: utf-8 -*- 2 3import os 4import datetime 5import json 6import sys 7import requests 8 9from urllib.parse import quote 10from time import sleep 11 12CUSTOM_SEARCH_URL = "https://www.googleapis.com/customsearch/v1/siterestrict?" 13 14 query = keyword+' after:'+day.strftime("%Y/%m/%d")+' before:'+nextday.strftime("%Y/%m/%d") 15 page_limit = 10 16 start_index = 1 17 response = [] 18 for n_page in range(0, page_limit): 19 try: 20 sleep(1) 21 22 #assemble queries 23 asquery = CUSTOM_SEARCH_URL + "key=" + GOOGLE_API_KEY + "&cx=" + CUSTOM_SEARCH_ENGINE_ID + "&num=10&start=" + str(start_index) + "&q=" + quote(query) 24 25 response_ele=requests.get(asquery) 26 response_ele= response_ele.json() 27 response.append(response_ele) 28 start_index = response_ele.get("queries").get("nextPage")[0].get("startIndex") 29 resuponse_ele = "" 30 except Exception as e: 31 print(e) 32 break 33/*この後responseをファイルに保存*/
試したこと
このスクリプトではクエリをプログラム中で作成し、requestsによってAPIを叩いていますが、ライブラリ[google-api-python-client]を利用したスクリプトでも同様の結果となりました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/04/21 13:27
2020/04/21 13:32
2020/04/21 13:34
2020/04/21 13:50