Let's dig into the documentation to find the answer!
The error appears on a call to the execute function of the batch object. So what kind of an object is batch?
It was returned from a call to the new_batch_http_request of the service object. So what kind of an object is service?
It's not created in the reference code you cited, so we have to rummage around in the document to find some other code where something named service
is created. The authors probably assumed that service in this example is the same kind of object.
The Quickstart page for Python seems like a good place to look and sure enough, there is code that creates an object named service
there:
service = build('classroom', 'v1', credentials=creds)
So we can guess that service was returned from a call to build. So what is build?
It's defined in that same sample:
from googleapiclient.discovery import build
So now we have to find the documentation for googleapiclient.discovery. A search for that name leads us to:
https://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.discovery-module.html
Here we see that the build function returns a Resource. So service is a Resource.
But when we look at the documentation for Resource, it has no function new_batch_http_request. What foul treachery is this?
"new_batch_http_request" looks like a pretty distinctive string, so we can search for that. Let's try the search box of the Google Classroom API site.
It only finds the Batching Requests page where we started. But it also offers to search all of Google Developers. So let's do that.
The search results then show that there are a lot of APIs with functions with this name and they all seem to create BatchHttpRequest objects, so the one for Resource probably does, too. So what is a BatchHttpRequest? Let's do another search for this name!
It turns out to be documented as part of the http module of the googleapiclient package at
https://googleapis.github.io/google-api-python-client/docs/epy/googleapiclient.http.BatchHttpRequest-class.html
The error came from a call to the execute function of the batch object, which we have guessed to be a BatchHttpRequest. Fortunately, a BatchHttpRequest has an execute function and that execute function takes an http argument. The documentation of the execute function says that the http argument can be omitted, but if it is supplied, it should be an httplib2.Http.
The reference code passes an object called http
as the parameter also called http
, but doesn't bother to construct it. That's why the compiler is complaining that it's undefined.
So to get the code to compile, you should be able just to omit the http=http
parameter. Then maybe it will run and maybe it won't. If it doesn't, you will have to figure out how to construct an appropriate Http object using the httplib2 library, with documentation at:
https://httplib2.readthedocs.io/en/latest/libhttplib2.html#http-objects