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, or PATCH or the same HTTP methods as strings.

  • payload – POST, PUT, or PATCH payload (implies method is not GET, HEAD, or DELETE). This argument is ignored if the method is not POST, PUT, or PATCH.

  • 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, a ResponseTooLargeError 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 to 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 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 of None indicates that the behavior will be chosen by the underlying urlfetch implementation.

Returns

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.

Return type

object

Raises

urlfetch_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.

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.

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, or PATCH or the same HTTP methods as strings.

  • payload – POST, PUT, or PATCH payload (implies method is not GET, HEAD, or DELETE). This argument is ignored if the method is not POST, PUT, or PATCH.

  • 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, a ResponseTooLargeError 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 to 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 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 of None indicates that the behavior will be chosen by the underlying urlfetch implementation.

Returns

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.

Return type

object

Raises

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

Raises
  • 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

Returns

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()’s deadline 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: create_rpc(), fetch()

Parameters

value – The default value that you want to use for the deadline parameter of create_rpc().