krohling/bondai

google.search.py error

Closed this issue · 2 comments

Using the google_search tool
Thought: By using this query, I aim to find search results that might contain a direct URL to John McCarthy's photo on the Stanford website.
Arguments
query: John McCarthy photo site:jmc.stanford.edu
count: 20
page: 1
An Error occured: <HttpError 400 when requesting https://customsearch.googleapis.com/customsearch/v1?q=John+McCarthy+photo+site%3Ajmc.stanford.edu&cx=500b5dd06afd248bb&start=0&num=20&key=AIzaSyAwHX-cA2ql81tbyczUAYAMajNe3qQ_vGA&alt=json returned "Request contains an invalid argument.". Details: "[{'message': 'Request contains an invalid argument.', 'domain': 'global', 'reason': 'badRequest'}]">

URL:
https://customsearch.googleapis.com/customsearch/v1?q=John+McCarthy+photo+site%3Ajmc.stanford.edu&cx=500b5dd06afd248bb&start=0&num=20&key=AIzaSyAwHX-cA2ql81tbyczUAYAMajNe3qQ_vGA&alt=json

Error:

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "errors": [
      {
        "message": "Request contains an invalid argument.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

If you change num=20 in the URL to a number less than 5 it works.

https://customsearch.googleapis.com/customsearch/v1?q=John+McCarthy+photo+site%3Ajmc.stanford.edu&cx=500b5dd06afd248bb&start=0&num=4&key=AIzaSyAwHX-cA2ql81tbyczUAYAMajNe3qQ_vGA&alt=json

E.G:

{
  "kind": "customsearch#search",
  "url": {
    "type": "application/json",
    "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
  },
  "queries": {
    "request": [
      {
        "title": "Google Custom Search - John McCarthy photo",
        "totalResults": "49000000",
        "searchTerms": "John McCarthy photo",
        "count": 4,
        "startIndex": 1,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "safe": "off",
        "cx": "500b5dd06afd248bb"
      }
    ],
    "nextPage": [
      {
        "title": "Google Custom Search - John McCarthy photo",
        "totalResults": "49000000",
        "searchTerms": "John McCarthy photo",
        "count": 4,
        "startIndex": 5,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "safe": "off",
        "cx": "500b5dd06afd248bb"
      }
    ]
  },
  "context": {
    "title": "Aura"
  },
  "searchInformation": {
    "searchTime": 0.219098,
    "formattedSearchTime": "0.22",
    "totalResults": "49000000",
    "formattedTotalResults": "49,000,000"
  },
  "items": [
    {
      "kind": "customsearch#result",
      "title": "jon-mccarthy-photo Jon McCarthy Photo",
      "htmlTitle": "<b>jon</b>-<b>mccarthy</b>-<b>photo Jon McCarthy Photo</b>",
      "link": "https://www.jonmccarthyphoto.com/",
      "displayLink": "www.jonmccarthyphoto.com",
      "snippet": "Portfolio- AT THE SHOW AT THE FARM IN THE PRESS -2023 Shows- -2022 Shows- INSTAGRAM | FACEBOOK.",
      "htmlSnippet": "Portfolio- AT THE SHOW AT THE FARM IN THE PRESS -2023 Shows- -2022 Shows- INSTAGRAM | FACEBOOK.",
      "cacheId": "szssU1TA40YJ",
      // etc

According to Google's documentation:
https://developers.google.com/custom-search/v1/reference/rest/v1/cse/list
num | integer
Number of search results to return.Valid values are integers between 1 and 10, inclusive.

I'll update the max result count value to 10. Thank for the heads up!

Ok, this was resolved in release 0.2.9. Thanks for the heads up!