Batches multiple HttpRequest objects into a single HTTP request. Example: from googleapiclient.http import BatchHttpRequest def list_animals(request_id, response, exception): \"\"\"Do something with the animals list response.\"\"\" if exception is not None:
| 1163 | |
| 1164 | |
| 1165 | class BatchHttpRequest(object): |
| 1166 | """Batches multiple HttpRequest objects into a single HTTP request. |
| 1167 | |
| 1168 | Example: |
| 1169 | from googleapiclient.http import BatchHttpRequest |
| 1170 | |
| 1171 | def list_animals(request_id, response, exception): |
| 1172 | \"\"\"Do something with the animals list response.\"\"\" |
| 1173 | if exception is not None: |
| 1174 | # Do something with the exception. |
| 1175 | pass |
| 1176 | else: |
| 1177 | # Do something with the response. |
| 1178 | pass |
| 1179 | |
| 1180 | def list_farmers(request_id, response, exception): |
| 1181 | \"\"\"Do something with the farmers list response.\"\"\" |
| 1182 | if exception is not None: |
| 1183 | # Do something with the exception. |
| 1184 | pass |
| 1185 | else: |
| 1186 | # Do something with the response. |
| 1187 | pass |
| 1188 | |
| 1189 | service = build('farm', 'v2') |
| 1190 | |
| 1191 | batch = BatchHttpRequest() |
| 1192 | |
| 1193 | batch.add(service.animals().list(), list_animals) |
| 1194 | batch.add(service.farmers().list(), list_farmers) |
| 1195 | batch.execute(http=http) |
| 1196 | """ |
| 1197 | |
| 1198 | @util.positional(1) |
| 1199 | def __init__(self, callback=None, batch_uri=None): |
| 1200 | """Constructor for a BatchHttpRequest. |
| 1201 | |
| 1202 | Args: |
| 1203 | callback: callable, A callback to be called for each response, of the |
| 1204 | form callback(id, response, exception). The first parameter is the |
| 1205 | request id, and the second is the deserialized response object. The |
| 1206 | third is an googleapiclient.errors.HttpError exception object if an HTTP error |
| 1207 | occurred while processing the request, or None if no error occurred. |
| 1208 | batch_uri: string, URI to send batch requests to. |
| 1209 | """ |
| 1210 | if batch_uri is None: |
| 1211 | batch_uri = _LEGACY_BATCH_URI |
| 1212 | |
| 1213 | if batch_uri == _LEGACY_BATCH_URI: |
| 1214 | LOGGER.warning( |
| 1215 | "You have constructed a BatchHttpRequest using the legacy batch " |
| 1216 | "endpoint %s. This endpoint will be turned down on August 12, 2020. " |
| 1217 | "Please provide the API-specific endpoint or use " |
| 1218 | "service.new_batch_http_request(). For more details see " |
| 1219 | "https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html" |
| 1220 | "and https://developers.google.com/api-client-library/python/guide/batch.", |
| 1221 | _LEGACY_BATCH_URI, |
| 1222 | ) |
no outgoing calls
searching dependent graphs…