Batch Request returns 404 "Not Found"
See original GitHub issueHi guys, I’m having a recent issue
def aggregate_response(request_id, response, exception):
if exception is not None:
# handle exception
print('An exception occurred: ', exception)
else:
# handle response
print('request_id is: ', request_id)
print('response is: ', response)
def batch_processor(queryset):
service = build('customsearch', 'v1')
batch = service.new_batch_http_request(callback=aggregate_response)
for result_instance in queryset:
search_query = {
'name': result_instance.name,
'status': result_instance.status,
}
query = f"{search_query['name']} {search_query['status']}"
# query is just a name string
batch.add(service.cse().list(
q=query,
cx=os.environ.get("SEARCH_ENGINE_ID"),
hl='en',
lr='lang_en',
num=3,
sort='date',
orTerms=search_query['name'],
key=os.environ.get("SEARCH_API_KEY"),
))
batch.execute()
I keep getting an exception: An exception occurred: <HttpError 404 when requesting https://www.googleapis.com/customsearch/v1?q={q}&cx={cx}&hl=en&lr=lang_en&num=3&sort=date&orTerms={orTerms}&key={key}&alt=json returned “Not Found”> However, clicking on the link https://www.googleapis.com/customsearch/v1?q={q}&cx={cx}&hl=en&lr=lang_en&num=3&sort=date&orTerms={orTerms}&key={key}&alt=json returns valid data.
I did some digging and I think the problem is related to the batch_uri
/ _LEGACY_BATCH_URI = 'https://www.googleapis.com/batch'
(the trailing /batch
) found in the googleapiclient/http.py
file.
Going to https://www.googleapis.com/batch/customsearch/v1?q={q}&cx={cx}&hl=en&lr=lang_en&num=3&sort=date&orTerms={orTerms}&key={key}&alt=json returns “Not Found”, however removing the trailing /batch
from _LEGACY_BATCH_URI
value doesn’t fix it.
P.S.: This was working until recently. Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Ok, thanks. Fingers crossed 🤞
This appears to be resolved. I was able to get the expected results using the script above.