google.appengine.api.urlfetch module

URL downloading API.

Methods defined in this module:
Fetch(): fetchs a given URL using an HTTP request using on of the methods
GET, POST, HEAD, PUT, DELETE or PATCH request
google.appengine.api.urlfetch.Fetch(url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, deadline=None, validate_certificate=None)

Fetches the given HTTP URL, blocking until the result is returned.

Other optional parameters are:
method: The constants GET, POST, HEAD, PUT, DELETE, or PATCH or the
same HTTP methods as strings.
payload: POST, PUT, or PATCH payload (implies method is not GET, HEAD,
or DELETE). this is ignored if the method is not POST, PUT, or PATCH.

headers: dictionary of HTTP headers to send with the request allow_truncated: if true, truncate large responses and return them without

error. Otherwise, ResponseTooLargeError is raised when a response is truncated.
follow_redirects: if true (the default), redirects are
transparently followed and the response (if less than 5 redirects) contains the final destination’s payload and the response status is 200. You lose, however, the redirect chain information. If false, 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 true, do not send request to server unless the

certificate is valid, signed by a trusted CA and the hostname matches the certificate. A value of None indicates that the behaviour will be chosen by the underlying urlfetch implementation.

We use a HTTP/1.1 compliant proxy to fetch the result.

The returned data structure has the following fields:
content: string containing the response from the server status_code: HTTP status code returned by the server headers: dictionary of headers returned by the server

If the URL is an empty string or obviously invalid, we throw an urlfetch.InvalidURLError. If the server cannot be contacted, we throw a urlfetch.DownloadError. Note that HTTP errors are returned as a part of the returned structure, so HTTP errors like 404 do not result in an exception.

google.appengine.api.urlfetch.create_rpc(deadline=None, callback=None)[source]

Creates an RPC object for use with the urlfetch API.

Args:
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.

Returns:
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.

Other optional parameters are:
method: The constants GET, POST, HEAD, PUT, DELETE, or PATCH or the
same HTTP methods as strings.
payload: POST, PUT, or PATCH payload (implies method is not GET, HEAD,
or DELETE). this is ignored if the method is not POST, PUT, or PATCH.

headers: dictionary of HTTP headers to send with the request allow_truncated: if true, truncate large responses and return them without

error. Otherwise, ResponseTooLargeError is raised when a response is truncated.
follow_redirects: if true (the default), redirects are
transparently followed and the response (if less than 5 redirects) contains the final destination’s payload and the response status is 200. You lose, however, the redirect chain information. If false, 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 true, do not send request to server unless the

certificate is valid, signed by a trusted CA and the hostname matches the certificate. A value of None indicates that the behaviour will be chosen by the underlying urlfetch implementation.

We use a HTTP/1.1 compliant proxy to fetch the result.

The returned data structure has the following fields:
content: string containing the response from the server status_code: HTTP status code returned by the server headers: dictionary of headers returned by the server

If the URL is an empty string or obviously invalid, we throw an urlfetch.InvalidURLError. If the server cannot be contacted, we throw a urlfetch.DownloadError. Note that HTTP errors are returned as a part of the returned structure, so HTTP errors like 404 do not result in an exception.

google.appengine.api.urlfetch.get_default_fetch_deadline()[source]

Get 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 urlfetch.fetch for a thorough description of remaining arguments.

Raises:

InvalidMethodError: if requested method is not in _VALID_METHODS ResponseTooLargeError: if the response payload is too large InvalidURLError: if there are issues with the content/size of the

requested URL
Returns:
The rpc object passed into the function.
google.appengine.api.urlfetch.set_default_fetch_deadline(value)[source]

Set the default value for create_rpc()’s deadline parameter.

This setting is thread-specific (i.e. it’s stored in a thread local). This function doesn’t do any range or type checking of the value. The default is None.

See also: create_rpc(), fetch()