I am working with the Google Search API, and I am running into some trouble. This request (in Python, using the requests library) works fine
res = requests.get("https://www.googleapis.com/customsearch/v1", params={
"cx": <key1>,
"key": <key2>,
"alt": "json",
"num": 2,
"q": "cat sock ship hero monkey baby match"
})
and returns results with the syntax according to the documentation
However, this request does not work:
res = requests.get("https://www.googleapis.com/customsearch/v1", params={
"cx": <key1>,
"key": <key2>,
"alt": "json",
"num": 2,
"q": "cat sock ship hero monkey footnoteref baby match"
})
it returns this:
{'kind': 'customsearch#search',
'queries': {'request': [{'count': 2,
'cx': '<key>',
'inputEncoding': 'utf8',
'outputEncoding': 'utf8',
'safe': 'off',
'searchTerms': 'cat sock ship hero monkey baby footnoteref match',
'title': 'Google Custom Search - cat sock ship hero monkey baby footnoteref match',
'totalResults': '0'}]},
'searchInformation': {'formattedSearchTime': '0.22',
'formattedTotalResults': '0',
'searchTime': 0.218722,
'totalResults': '0'},
'spelling': {'correctedQuery': 'cat sock ship hero monkey baby footnote ref match',
'htmlCorrectedQuery': 'cat sock ship hero monkey baby <b><i>footnote ref</i></b> match'},
'url': {'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',
'type': 'application/json'}}
The only difference between the two queries is that the latter has the word "footnoteref" in it. I did not find in the documentation anything about this word and its impact on the API's behavior. What is happening? Is there a way to disable this behavior, or a list of reserved words? For now, I am just going to remove the offending word from the query, but I am afraid I am going to play a whack-a-mole game of removing words each time other offending word pops out.