Execute the request. Args: http: httplib2.Http, an http object to be used in place of the one the HttpRequest request object was constructed with. num_retries: Integer, number of times to retry with randomized exponential backoff. If all r
(self, http=None, num_retries=0)
| 875 | |
| 876 | @util.positional(1) |
| 877 | def execute(self, http=None, num_retries=0): |
| 878 | """Execute the request. |
| 879 | |
| 880 | Args: |
| 881 | http: httplib2.Http, an http object to be used in place of the |
| 882 | one the HttpRequest request object was constructed with. |
| 883 | num_retries: Integer, number of times to retry with randomized |
| 884 | exponential backoff. If all retries fail, the raised HttpError |
| 885 | represents the last request. If zero (default), we attempt the |
| 886 | request only once. |
| 887 | |
| 888 | Returns: |
| 889 | A deserialized object model of the response body as determined |
| 890 | by the postproc. |
| 891 | |
| 892 | Raises: |
| 893 | googleapiclient.errors.HttpError if the response was not a 2xx. |
| 894 | httplib2.HttpLib2Error if a transport error has occurred. |
| 895 | """ |
| 896 | if http is None: |
| 897 | http = self.http |
| 898 | |
| 899 | if self.resumable: |
| 900 | body = None |
| 901 | while body is None: |
| 902 | _, body = self.next_chunk(http=http, num_retries=num_retries) |
| 903 | return body |
| 904 | |
| 905 | # Non-resumable case. |
| 906 | |
| 907 | if "content-length" not in self.headers: |
| 908 | self.headers["content-length"] = str(self.body_size) |
| 909 | # If the request URI is too long then turn it into a POST request. |
| 910 | # Assume that a GET request never contains a request body. |
| 911 | if len(self.uri) > MAX_URI_LENGTH and self.method == "GET": |
| 912 | self.method = "POST" |
| 913 | self.headers["x-http-method-override"] = "GET" |
| 914 | self.headers["content-type"] = "application/x-www-form-urlencoded" |
| 915 | parsed = urllib.parse.urlparse(self.uri) |
| 916 | self.uri = urllib.parse.urlunparse( |
| 917 | (parsed.scheme, parsed.netloc, parsed.path, parsed.params, None, None) |
| 918 | ) |
| 919 | self.body = parsed.query |
| 920 | self.headers["content-length"] = str(len(self.body)) |
| 921 | |
| 922 | # Handle retries for server-side errors. |
| 923 | resp, content = _retry_request( |
| 924 | http, |
| 925 | num_retries, |
| 926 | "request", |
| 927 | self._sleep, |
| 928 | self._rand, |
| 929 | str(self.uri), |
| 930 | method=str(self.method), |
| 931 | body=self.body, |
| 932 | headers=self.headers, |
| 933 | ) |
| 934 |