MCPcopy Index your code
hub / github.com/googleapis/google-api-python-client / execute

Method execute

googleapiclient/http.py:1528–1606  ·  view source on GitHub ↗

Execute all the requests as a single batched HTTP request. Args: http: httplib2.Http, an http object to be used in place of the one the HttpRequest request object was constructed with. If one isn't supplied then use a http object from the requests in this b

(self, http=None)

Source from the content-addressed store, hash-verified

1526
1527 @util.positional(1)
1528 def execute(self, http=None):
1529 """Execute all the requests as a single batched HTTP request.
1530
1531 Args:
1532 http: httplib2.Http, an http object to be used in place of the one the
1533 HttpRequest request object was constructed with. If one isn't supplied
1534 then use a http object from the requests in this batch.
1535
1536 Returns:
1537 None
1538
1539 Raises:
1540 httplib2.HttpLib2Error if a transport error has occurred.
1541 googleapiclient.errors.BatchError if the response is the wrong format.
1542 """
1543 # If we have no requests return
1544 if len(self._order) == 0:
1545 return None
1546
1547 # If http is not supplied use the first valid one given in the requests.
1548 if http is None:
1549 for request_id in self._order:
1550 request = self._requests[request_id]
1551 if request is not None:
1552 http = request.http
1553 break
1554
1555 if http is None:
1556 raise ValueError("Missing a valid http object.")
1557
1558 # Special case for OAuth2Credentials-style objects which have not yet been
1559 # refreshed with an initial access_token.
1560 creds = _auth.get_credentials_from_http(http)
1561 if creds is not None:
1562 if not _auth.is_valid(creds):
1563 LOGGER.info("Attempting refresh to obtain initial access_token")
1564 _auth.refresh_credentials(creds)
1565
1566 self._execute(http, self._order, self._requests)
1567
1568 # Loop over all the requests and check for 401s. For each 401 request the
1569 # credentials should be refreshed and then sent again in a separate batch.
1570 redo_requests = {}
1571 redo_order = []
1572
1573 for request_id in self._order:
1574 resp, content = self._responses[request_id]
1575 if resp["status"] == "401":
1576 redo_order.append(request_id)
1577 request = self._requests[request_id]
1578 self._refresh_and_apply_credentials(request, http)
1579 redo_requests[request_id] = request
1580
1581 if redo_requests:
1582 self._execute(http, redo_order, redo_requests)
1583
1584 # Now process all callbacks that are erroring, and raise an exception for
1585 # ones that return a non-2xx response? Or add extra parameter to callback

Calls 4

_executeMethod · 0.95
HttpErrorClass · 0.90
infoMethod · 0.80