HttpResponse Class

Abstract base class for HTTP responses.

Use this abstract base class to create your own transport responses.

Responses implementing this ABC are returned from your client's send_request method if you pass in an HttpRequest


>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest('GET', 'http://www.example.com')
<HttpRequest [GET], url: 'http://www.example.com'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>
Inheritance
azure.core.rest._rest_py3._HttpResponseBase
HttpResponse

Constructor

HttpResponse()

Methods

close
iter_bytes

Iterates over the response's bytes. Will decompress in the process.

iter_raw

Iterates over the response's bytes. Will not decompress in the process.

json

Returns the whole body as a json object.

raise_for_status

Raises an HttpResponseError if the response has an error status code.

If response is good, does nothing.

read

Read the response's bytes.

text

Returns the response body as a string.

close

abstract close() -> None

iter_bytes

Iterates over the response's bytes. Will decompress in the process.

abstract iter_bytes(**kwargs: Any) -> Iterator[bytes]

Returns

Type Description

An iterator of bytes from the response

iter_raw

Iterates over the response's bytes. Will not decompress in the process.

abstract iter_raw(**kwargs: Any) -> Iterator[bytes]

Returns

Type Description

An iterator of bytes from the response

json

Returns the whole body as a json object.

abstract json() -> Any

Returns

Type Description
any

The JSON deserialized response body

Exceptions

Type Description
json.decoder.JSONDecodeError
in python 2.7
if object is not JSON decodable

raise_for_status

Raises an HttpResponseError if the response has an error status code.

If response is good, does nothing.

abstract raise_for_status() -> None

Exceptions

Type Description
azure.core.HttpResponseError if the object has an error status code.

read

Read the response's bytes.

abstract read() -> bytes

Returns

Type Description

The read in bytes

text

Returns the response body as a string.

abstract text(encoding: str | None = None) -> str

Parameters

Name Description
encoding
<xref:optional>[str]

The encoding you want to decode the text with. Can also be set independently through our encoding property

default value: None

Returns

Type Description
str

The response's content decoded as a string.

Attributes

content

content_type

encoding

headers

is_closed

is_stream_consumed

reason

request

status_code

url