本文整理汇总了Python中googleapiclient.http.HttpRequest方法的典型用法代码示例。如果您正苦于以下问题:Python http.HttpRequest方法的具体用法?Python http.HttpRequest怎么用?Python http.HttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类googleapiclient.http
的用法示例。
在下文中一共展示了http.HttpRequest方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_report_file
# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import HttpRequest [as 别名]
def get_report_file(
self, file_id: str, profile_id: str, report_id: str
) -> http.HttpRequest:
"""
Retrieves a media part of report file.
:param profile_id: The DFA user profile ID.
:type profile_id: str
:param report_id: The ID of the report.
:type report_id: str
:param file_id: The ID of the report file.
:type file_id: str
:return: googleapiclient.http.HttpRequest
"""
request = (
self.get_conn() # pylint: disable=no-member
.reports()
.files()
.get_media(fileId=file_id, profileId=profile_id, reportId=report_id)
)
return request
示例2: __init__
# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import HttpRequest [as 别名]
def __init__(self, http, baseUrl, model, requestBuilder, developerKey,
resourceDesc, rootDesc, schema):
"""Build a Resource from the API description.
Args:
http: httplib2.Http, Object to make http requests with.
baseUrl: string, base URL for the API. All requests are relative to this
URI.
model: googleapiclient.Model, converts to and from the wire format.
requestBuilder: class or callable that instantiates an
googleapiclient.HttpRequest object.
developerKey: string, key obtained from
https://code.google.com/apis/console
resourceDesc: object, section of deserialized discovery document that
describes a resource. Note that the top level discovery document
is considered a resource.
rootDesc: object, the entire deserialized discovery document.
schema: object, mapping of schema names to schema descriptions.
"""
self._dynamic_attrs = []
self._http = http
self._baseUrl = baseUrl
self._model = model
self._developerKey = developerKey
self._requestBuilder = requestBuilder
self._resourceDesc = resourceDesc
self._rootDesc = rootDesc
self._schema = schema
self._set_service_methods()
示例3: send_all
# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import HttpRequest [as 别名]
def send_all(self, messages, dry_run=False):
"""Sends the given messages to FCM via the batch API."""
if not isinstance(messages, list):
raise ValueError('messages must be a list of messaging.Message instances.')
if len(messages) > 500:
raise ValueError('messages must not contain more than 500 elements.')
responses = []
def batch_callback(_, response, error):
exception = None
if error:
exception = self._handle_batch_error(error)
send_response = SendResponse(response, exception)
responses.append(send_response)
batch = http.BatchHttpRequest(
callback=batch_callback, batch_uri=_MessagingService.FCM_BATCH_URL)
for message in messages:
body = json.dumps(self._message_data(message, dry_run))
req = http.HttpRequest(
http=self._transport,
postproc=self._postproc,
uri=self._fcm_url,
method='POST',
body=body,
headers=self._fcm_headers
)
batch.add(req)
try:
batch.execute()
except googleapiclient.http.HttpError as error:
raise self._handle_batch_error(error)
else:
return BatchResponse(responses)
示例4: _execute_request
# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import HttpRequest [as 别名]
def _execute_request(
self,
request: http.HttpRequest) -> Mapping[Text, Sequence[Mapping[Text, Any]]]:
result = request.execute()
if 'error' in result:
raise ValueError(result['error'])
return result
示例5: _make_request
# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import HttpRequest [as 别名]
def _make_request(self, body: Mapping[Text, List[Any]]) -> http.HttpRequest:
return self._api_client.projects().predict(
name=self._full_model_name, body=body)
示例6: build
# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import HttpRequest [as 别名]
def build(serviceName,
version,
http=None,
discoveryServiceUrl=DISCOVERY_URI,
developerKey=None,
model=None,
requestBuilder=HttpRequest,
credentials=None,
cache_discovery=True,
cache=None):
"""Construct a Resource for interacting with an API.
Construct a Resource object for interacting with an API. The serviceName and
version are the names from the Discovery service.
Args:
serviceName: string, name of the service.
version: string, the version of the service.
http: httplib2.Http, An instance of httplib2.Http or something that acts
like it that HTTP requests will be made through.
discoveryServiceUrl: string, a URI Template that points to the location of
the discovery service. It should have two parameters {api} and
{apiVersion} that when filled in produce an absolute URI to the discovery
document for that service.
developerKey: string, key obtained from
https://code.google.com/apis/console.
model: googleapiclient.Model, converts to and from the wire format.
requestBuilder: googleapiclient.http.HttpRequest, encapsulator for an HTTP
request.
credentials: oauth2client.Credentials, credentials to be used for
authentication.
cache_discovery: Boolean, whether or not to cache the discovery doc.
cache: googleapiclient.discovery_cache.base.CacheBase, an optional
cache object for the discovery documents.
Returns:
A Resource object with methods for interacting with the service.
"""
params = {
'api': serviceName,
'apiVersion': version
}
if http is None:
http = httplib2.Http()
requested_url = uritemplate.expand(discoveryServiceUrl, params)
try:
content = _retrieve_discovery_doc(requested_url, http, cache_discovery,
cache)
except HttpError as e:
if e.resp.status == http_client.NOT_FOUND:
raise UnknownApiNameOrVersion("name: %s version: %s" % (serviceName,
version))
else:
raise e
return build_from_document(content, base=discoveryServiceUrl, http=http,
developerKey=developerKey, model=model, requestBuilder=requestBuilder,
credentials=credentials)