Python 2.7 has reached end of support
and will bedeprecatedon January 31, 2026. After deprecation, you won't be able to deploy Python 2.7
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Python
2.7 applications will continue to run and receive traffic after theirdeprecation date. We recommend that
youmigrate to the latest supported version of Python.
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 constantsGET,POST,HEAD,PUT,DELETE, orPATCHor
the same HTTP methods as strings.
payload –POST,PUT, orPATCHpayload (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 toTrue, truncates large responses and returns
them without raising an error. Otherwise, aResponseTooLargeErroris
raised when a response is truncated.
follow_redirects – If set toTrue(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 toTrue, 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 ofNoneindicates that the
behavior will be chosen by the underlyingurlfetchimplementation.
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 theurlfetch_errorsmodule
for more information.
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 constantsGET,POST,HEAD,PUT,DELETE, orPATCHor
the same HTTP methods as strings.
payload –POST,PUT, orPATCHpayload (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 toTrue, truncates large responses and returns
them without raising an error. Otherwise, aResponseTooLargeErroris
raised when a response is truncated.
follow_redirects – If set toTrue(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 toTrue, 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 ofNoneindicates that the
behavior will be chosen by the underlyingurlfetchimplementation.
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 theurlfetch_errorsmodule
for more information.
Sets the default value forcreate_rpc()’sdeadlineparameter.
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 isNone.
See also:create_rpc(),fetch()
Parameters
value – The default value that you want to use for thedeadlineparameter
ofcreate_rpc().
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003eThe \u003ccode\u003egoogle.appengine.api.urlfetch\u003c/code\u003e module provides an API for downloading content from HTTP URLs, supporting methods like GET, POST, HEAD, PUT, DELETE, and PATCH.\u003c/p\u003e\n"],["\u003cp\u003eThe primary function, \u003ccode\u003efetch\u003c/code\u003e, retrieves content from a specified URL and returns an object with the content, status code, and headers.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecreate_rpc\u003c/code\u003e function creates an RPC object for use with the urlfetch API, allowing for more complex asynchronous URL fetching operations.\u003c/p\u003e\n"],["\u003cp\u003eYou can customize requests with parameters such as \u003ccode\u003emethod\u003c/code\u003e, \u003ccode\u003epayload\u003c/code\u003e, \u003ccode\u003eheaders\u003c/code\u003e, \u003ccode\u003eallow_truncated\u003c/code\u003e, \u003ccode\u003efollow_redirects\u003c/code\u003e, \u003ccode\u003edeadline\u003c/code\u003e, and \u003ccode\u003evalidate_certificate\u003c/code\u003e to control the behavior of the fetching operation.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eset_default_fetch_deadline\u003c/code\u003e and \u003ccode\u003eget_default_fetch_deadline\u003c/code\u003e allow you to set and get a time limit for fetching a url, and it is stored on a per-thread basis.\u003c/p\u003e\n"]]],[],null,["# google.appengine.api.urlfetch module\n====================================\n\nSummary\n-------\n\nURL downloading API.\n\nContents\n--------\n\ngoogle.appengine.api.urlfetch.Fetch(url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, deadline=None, validate_certificate=None)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/urlfetch#fetch)\n\n: Fetches the given HTTP URL, blocking until the result is returned.\n\n URLs are fetched using one of the following HTTP methods:\n :\n - GET\n\n - POST\n\n - HEAD\n\n - PUT\n\n - DELETE\n\n - PATCH\n\n\n To fetch the result, a HTTP/1.1-compliant proxy is used.\n Parameters\n\n - method -- The constants `GET`, `POST`, `HEAD`, `PUT`, `DELETE`, or `PATCH` or\n the same HTTP methods as strings.\n\n - payload -- `POST`, `PUT`, or `PATCH` payload (implies method is not `GET`,\n `HEAD`, or `DELETE`). This argument is ignored if the method is not\n `POST`, `PUT`, or `PATCH`.\n\n - headers -- Dictionary of HTTP headers to send with the request.\n\n - allow_truncated -- If set to `True`, truncates large responses and returns\n them without raising an error. Otherwise, a `ResponseTooLargeError` is\n raised when a response is truncated.\n\n - follow_redirects -- If set to `True` (the default), redirects are\n transparently followed, and the response (if less than 5 redirects)\n contains the final destination's payload; the response status is 200.\n You lose, however, the redirect chain information. If set to `False`,\n you see the HTTP response yourself, including the 'Location' header, and\n redirects are not followed.\n\n - deadline -- Deadline in seconds for the operation.\n\n - validate_certificate -- If set to `True`, requests are not sent to the server\n unless the certificate is valid, signed by a trusted CA, and the host\n name matches the certificate. A value of `None` indicates that the\n behavior will be chosen by the underlying `urlfetch` implementation.\n\n Returns\n\n\n An object containing following fields:\n\n - content: A string that contains the response from the server.\n\n - status_code: The HTTP status code that was returned by the server.\n\n - headers: The dictionary of headers that was returned by the server.\n\n \u003cbr /\u003e\n\n Return type\n\n object\n Raises\n\n urlfetch_errors.Error -- If an error occurs. See the [urlfetch_errors](http://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.urlfetch_errors) module\n for more information.\n | **Note:**\n |\n | HTTP errors are returned as a part of the return structure. HTTP errors\nlike 404 do not result in an exception. \n\ngoogle.appengine.api.urlfetch.create_rpc(deadline=None, callback=None)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/urlfetch#create_rpc)\n\n: Creates an RPC object for use with the urlfetch API.\n\n Parameters\n\n - deadline -- Optional deadline in seconds for the operation; the default\n is a system-specific deadline (typically 5 seconds).\n\n - callback -- Optional callable to invoke on completion.\n\n Returns\n\nAn `apiproxy_stub_map.UserRPC` object specialized for this service. \n\ngoogle.appengine.api.urlfetch.fetch(url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, deadline=None, validate_certificate=None)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/urlfetch#fetch)\n\n: Fetches the given HTTP URL, blocking until the result is returned.\n\n URLs are fetched using one of the following HTTP methods:\n :\n - GET\n\n - POST\n\n - HEAD\n\n - PUT\n\n - DELETE\n\n - PATCH\n\n\n To fetch the result, a HTTP/1.1-compliant proxy is used.\n Parameters\n\n - method -- The constants `GET`, `POST`, `HEAD`, `PUT`, `DELETE`, or `PATCH` or\n the same HTTP methods as strings.\n\n - payload -- `POST`, `PUT`, or `PATCH` payload (implies method is not `GET`,\n `HEAD`, or `DELETE`). This argument is ignored if the method is not\n `POST`, `PUT`, or `PATCH`.\n\n - headers -- Dictionary of HTTP headers to send with the request.\n\n - allow_truncated -- If set to `True`, truncates large responses and returns\n them without raising an error. Otherwise, a `ResponseTooLargeError` is\n raised when a response is truncated.\n\n - follow_redirects -- If set to `True` (the default), redirects are\n transparently followed, and the response (if less than 5 redirects)\n contains the final destination's payload; the response status is 200.\n You lose, however, the redirect chain information. If set to `False`,\n you see the HTTP response yourself, including the 'Location' header, and\n redirects are not followed.\n\n - deadline -- Deadline in seconds for the operation.\n\n - validate_certificate -- If set to `True`, requests are not sent to the server\n unless the certificate is valid, signed by a trusted CA, and the host\n name matches the certificate. A value of `None` indicates that the\n behavior will be chosen by the underlying `urlfetch` implementation.\n\n Returns\n\n\n An object containing following fields:\n\n - content: A string that contains the response from the server.\n\n - status_code: The HTTP status code that was returned by the server.\n\n - headers: The dictionary of headers that was returned by the server.\n\n \u003cbr /\u003e\n\n Return type\n\n object\n Raises\n\n urlfetch_errors.Error -- If an error occurs. See the [urlfetch_errors](http://cloud.google.com/appengine/docs/python/refdocs/google.appengine.api.urlfetch_errors) module\n for more information.\n | **Note:**\n |\n | HTTP errors are returned as a part of the return structure. HTTP errors\nlike 404 do not result in an exception. \n\ngoogle.appengine.api.urlfetch.get_default_fetch_deadline()[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/urlfetch#get_default_fetch_deadline)\n\n: Gets the default value for `create_rpc()`'s deadline parameter.\n\ngoogle.appengine.api.urlfetch.make_fetch_call(rpc, url, payload=None, method=1, headers={}, allow_truncated=False, follow_redirects=True, validate_certificate=None)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/urlfetch#make_fetch_call)\n\n: Executes the RPC call to fetch a given HTTP URL.\n\n The first argument is a UserRPC instance. See `urlfetch.fetch` for a\n thorough description of the remaining arguments.\n Raises\n\n - InvalidMethodError -- If the requested method is not in `_VALID_METHODS`.\n\n - ResponseTooLargeError -- If the response payload is too large.\n\n - InvalidURLError -- If there are issues with the content or size of the\n requested URL\n\n Returns\n\nThe RPC object that was passed into the function. \n\ngoogle.appengine.api.urlfetch.set_default_fetch_deadline(value)[source](/appengine/docs/legacy/standard/python/refdocs/modules/google/appengine/api/urlfetch#set_default_fetch_deadline)\n\n: Sets the default value for `create_rpc()`'s `deadline` parameter.\n\n This setting is thread-specific, meaning it that is stored in a thread local.\n This function doesn't check the type or range of the value. The default\n value is `None`.\n\n See also: `create_rpc()`, `fetch()`\n Parameters\n\n value -- The default value that you want to use for the `deadline` parameter\n of `create_rpc()`."]]