google.appengine.api.urlfetch module
Summary
URL downloading API.
Contents
- google.appengine.api.urlfetch.Fetch(url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, deadline=None, validate_certificate=None)source
Fetches the given HTTP URL, blocking until the result is returned.
- URLs are fetched using one of the following HTTP methods:
-
-
GET
-
POST
-
HEAD
-
PUT
-
DELETE
-
PATCH
-
To fetch the result, a HTTP/1.1-compliant proxy is used.
Parameters-
method – The constants
GET
,POST
,HEAD
,PUT
,DELETE
, orPATCH
or the same HTTP methods as strings. -
payload –
POST
,PUT
, orPATCH
payload (implies method is notGET
,HEAD
, orDELETE
). This argument is ignored if the method is notPOST
,PUT
, orPATCH
. -
headers – Dictionary of HTTP headers to send with the request.
-
allow_truncated – If set to
True
, truncates large responses and returns them without raising an error. Otherwise, aResponseTooLargeError
is raised when a response is truncated. -
follow_redirects – If set to
True
(the default), redirects are transparently followed, and the response (if less than 5 redirects) contains the final destination’s payload; the response status is 200. You lose, however, the redirect chain information. If set toFalse
, you see the HTTP response yourself, including the ‘Location’ header, and redirects are not followed. -
deadline – Deadline in seconds for the operation.
-
validate_certificate – If set to
True
, requests are not sent to the server unless the certificate is valid, signed by a trusted CA, and the host name matches the certificate. A value ofNone
indicates that the behavior will be chosen by the underlyingurlfetch
implementation.
An object containing following fields:
-
content: A string that contains the response from the server.
-
status_code: The HTTP status code that was returned by the server.
-
headers: The dictionary of headers that was returned by the server.
object
Raisesurlfetch_errors.Error – If an error occurs. See the urlfetch_errors module for more information.
- google.appengine.api.urlfetch.create_rpc(deadline=None, callback=None)source
Creates an RPC object for use with the urlfetch API.
Parameters-
deadline – Optional deadline in seconds for the operation; the default is a system-specific deadline (typically 5 seconds).
-
callback – Optional callable to invoke on completion.
An
apiproxy_stub_map.UserRPC
object specialized for this service.-
- google.appengine.api.urlfetch.fetch(url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, deadline=None, validate_certificate=None)source
Fetches the given HTTP URL, blocking until the result is returned.
- URLs are fetched using one of the following HTTP methods:
-
-
GET
-
POST
-
HEAD
-
PUT
-
DELETE
-
PATCH
-
To fetch the result, a HTTP/1.1-compliant proxy is used.
Parameters-
method – The constants
GET
,POST
,HEAD
,PUT
,DELETE
, orPATCH
or the same HTTP methods as strings. -
payload –
POST
,PUT
, orPATCH
payload (implies method is notGET
,HEAD
, orDELETE
). This argument is ignored if the method is notPOST
,PUT
, orPATCH
. -
headers – Dictionary of HTTP headers to send with the request.
-
allow_truncated – If set to
True
, truncates large responses and returns them without raising an error. Otherwise, aResponseTooLargeError
is raised when a response is truncated. -
follow_redirects – If set to
True
(the default), redirects are transparently followed, and the response (if less than 5 redirects) contains the final destination’s payload; the response status is 200. You lose, however, the redirect chain information. If set toFalse
, you see the HTTP response yourself, including the ‘Location’ header, and redirects are not followed. -
deadline – Deadline in seconds for the operation.
-
validate_certificate – If set to
True
, requests are not sent to the server unless the certificate is valid, signed by a trusted CA, and the host name matches the certificate. A value ofNone
indicates that the behavior will be chosen by the underlyingurlfetch
implementation.
An object containing following fields:
-
content: A string that contains the response from the server.
-
status_code: The HTTP status code that was returned by the server.
-
headers: The dictionary of headers that was returned by the server.
object
Raisesurlfetch_errors.Error – If an error occurs. See the urlfetch_errors module for more information.
- google.appengine.api.urlfetch.get_default_fetch_deadline()source
-
Gets the default value for
create_rpc()
’s deadline parameter.
- google.appengine.api.urlfetch.make_fetch_call(rpc, url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, validate_certificate=None)source
Executes the RPC call to fetch a given HTTP URL.
The first argument is a UserRPC instance. See
Raisesurlfetch.fetch
for a thorough description of the remaining arguments.-
InvalidMethodError – If the requested method is not in
_VALID_METHODS
. -
ResponseTooLargeError – If the response payload is too large.
-
InvalidURLError – If there are issues with the content or size of the requested URL
The RPC object that was passed into the function.
-
- google.appengine.api.urlfetch.set_default_fetch_deadline(value)source
Sets the default value for
create_rpc()
’sdeadline
parameter.This setting is thread-specific, meaning it that is stored in a thread local. This function doesn’t check the type or range of the value. The default value is
None
.See also:
Parameterscreate_rpc()
,fetch()
value – The default value that you want to use for the
deadline
parameter ofcreate_rpc()
.