AsyncHttpResponse Class
Abstract base class for Async HTTP responses.
Use this abstract base class to create your own transport responses.
Responses implementing this ABC are returned from your async 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 = await client.send_request(request)
<AsyncHttpResponse: 200 OK>
Constructor
AsyncHttpResponse()
Methods
| close | |
| iter_bytes |
Asynchronously iterates over the response's bytes. Will decompress in the process. |
| iter_raw |
Asynchronously 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 into memory. |
| text |
Returns the response body as a string. |
close
abstract async close() -> None
iter_bytes
Asynchronously iterates over the response's bytes. Will decompress in the process.
abstract async iter_bytes(**kwargs: Any) -> AsyncIterator[bytes]
Returns
| Type | Description |
|---|---|
|
An async iterator of bytes from the response |
iter_raw
Asynchronously iterates over the response's bytes. Will not decompress in the process.
abstract async iter_raw(**kwargs: Any) -> AsyncIterator[bytes]
Returns
| Type | Description |
|---|---|
|
An async iterator of bytes from the response |
json
Returns the whole body as a json object.
abstract json() -> Any
Returns
| Type | Description |
|---|---|
|
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 into memory.
abstract async read() -> bytes
Returns
| Type | Description |
|---|---|
|
The response's 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 |
|---|---|
|
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 |
|---|---|
|
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 |
|---|---|
|
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 |
|---|---|
|
The status code of this response. |
url
The URL that resulted in this response.
abstract property url: str
Returns
| Type | Description |
|---|---|
|
The URL that resulted in this response. |