你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

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>

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

if the body is not valid JSON.

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

Return the response's content in bytes.

abstract property content: bytes

Returns

Type Description

The response's content in bytes.

content_type

The content type of the response.

abstract property content_type: str | None

Returns

Type Description
str

The content type of the response.

encoding

Returns the response encoding.

abstract property encoding: str | None

Returns

Type Description
<xref:optional>[str]

The response encoding. We either return the encoding set by the user, or try extracting the encoding from the response's content type. If all fails, we return None.

headers

The response headers. Must be case-insensitive.

abstract property headers: MutableMapping[str, str]

Returns

Type Description

The response headers. Must be case-insensitive.

is_closed

Whether the network connection has been closed yet.

abstract property is_closed: bool

Returns

Type Description

Whether the network connection has been closed yet.

is_stream_consumed

Whether the stream has been consumed.

abstract property is_stream_consumed: bool

Returns

Type Description

Whether the stream has been consumed.

reason

The reason phrase for this response.

abstract property reason: str

Returns

Type Description
str

The reason phrase for this response.

request

The request that resulted in this response.

abstract property request: HttpRequest

Returns

Type Description

The request that resulted in this response.

status_code

The status code of this response.

abstract property status_code: int

Returns

Type Description
int

The status code of this response.

url

The URL that resulted in this response.

abstract property url: str

Returns

Type Description
str

The URL that resulted in this response.