The
fetch()
function makes a synchronous request to fetch a URL.
This function is provided by the
google.appengine.api.urlfetch
package.
See also Asychronous Requests .
- fetch ( url , payload = None , method = GET , headers = {} , allow_truncated = False , follow_redirects = True , deadline = 5 , validate_certificate = False )
-
Fetches a document at the URL given in url , and returns an object containing the details of the response. See Response Objects for details about the return value.
The fetch action is synchronous.
fetch()
will not return until the server responds. A slow remote server may cause your application's own request to time out.Arguments
- url
-
An
http
orhttps
URL. If the URL is invalid, anInvalidURLError
is raised. If you want to add query parameters in a GET request, append them to the URL, for example:https://www.example.com/?q=some+queryparam
. - payload
-
Body content for a
POST
,PUT
, orPATCH
request. - method
-
The HTTP method to use for the request. Acceptable values include
GET
,POST
,HEAD
,PUT
,DELETE
, andPATCH
. These values are constants provided by the package. The value can also be a string equivalent to the name of the method. - headers
- The set of HTTP headers to include with the request, as a mapping of names and values. For security reasons, some HTTP headers cannot be modified by the application. See the URL Fetch Service overview .
- allow_truncated
-
If
False
and the response data exceeds the maximum allowed response size, aResponseTooLargeError
exception is raised. IfTrue
, no exception is raised, and the response'scontent
is truncated to the maximum size, and the response object'scontent_was_truncated
attribute is set toTrue
. For more information on limits, see the URL Fetch Service overview . - follow_redirects
-
If
True
, responses that are HTTP redirects are followed, up to 5 consecutive redirects. The response data is from the final location, as if the data were for the requested location. IfFalse
, redirects are not followed, and a redirect response is returned directly to the application, including the header information that describes the redirect.Warning: Cookies are not handled upon redirection. If cookie handling is needed, set follow_redirects to
False
and handle both cookies and redirects manually. - deadline
-
The maximum amount of time to wait for a response from the remote host, as a number of seconds. If this parameter is not specified, the default value used will be a system-specific deadline, which is typically 5 seconds. If the remote host does not respond in this amount of time, a
DownloadError
is raised.Time spent waiting for a request does not count toward the CPU quota for the request. It does count toward the request timer. If the app request timer expires before the URL Fetch call returns, the call is canceled.
The deadline can be up to a maximum of 60 seconds for request handlers and 10 minutes for tasks queue and cron job handlers.
- validate_certificate
-
A value of
True
instructs the application to send a request to the server only if the certificate is valid and signed by a trusted certificate authority (CA), and also includes a hostname that matches the certificate. If the certificate validation fails, aSSLCertificateError
exception is raised. A value ofFalse
instructs the application to perform no certificate validation. This parameter is ignored for non-HTTPS requests.Note: This parameter currently defaults to
False
, but will default toTrue
in the near future. If you rely upon making requests to a site with an invalid or untrusted certificate, you should explicitly passvalidate_certificate=False
to avoid errors in future versions.