class QRestReply

QRestReply is a convenience wrapper for QNetworkReply . More

Added in version 6.7.

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

QRestReply wraps a QNetworkReply and provides convenience methods for data and status handling. The methods provide convenience for typical RESTful client applications.

QRestReply doesn’t take ownership of the wrapped QNetworkReply , and the lifetime and ownership of the reply is as defined by QNetworkAccessManager documentation.

QRestReply object is not copyable, but is movable.

__init__(reply)
Parameters:

replyQNetworkReply

Creates a QRestReply and initializes the wrapped QNetworkReply to reply.

error()
Return type:

NetworkError

Returns the last error, if any. The errors include errors such as network and protocol errors, but exclude cases when the server successfully responded with an HTTP status.

errorString()
Return type:

str

Returns a human-readable description of the last network error.

hasError()
Return type:

bool

Returns whether an error has occurred. This includes errors such as network and protocol errors, but excludes cases where the server successfully responded with an HTTP error status (for example 500 Internal Server Error). Use httpStatus() or isHttpStatusSuccess() to get the HTTP status information.

httpStatus()
Return type:

int

Returns the HTTP status received in the server response. The value is 0 if not available (the status line has not been received, yet).

Note

The HTTP status is reported as indicated by the received HTTP response. An error() may occur after receiving the status, for instance due to network disconnection while receiving a long response. These potential subsequent errors are not represented by the reported HTTP status.

isHttpStatusSuccess()
Return type:

bool

Returns whether the HTTP status is between 200..299.

isSuccess()
Return type:

bool

Returns whether the HTTP status is between 200..299 and no further errors have occurred while receiving the response (for example, abrupt disconnection while receiving the body data). This function is a convenient way to check whether the response is considered successful.

networkReply()
Return type:

QNetworkReply

Returns a pointer to the underlying QNetworkReply wrapped by this object.

readBody()
Return type:

QByteArray

Returns the received data as a QByteArray.

Calling this function consumes the data received so far, and any further calls to get response data will return empty until further data has been received.

See also

readJson() readText() readyRead()

readJson()
Return type:

object

readText()
Return type:

str

Returns the received data as a QString.

The received data is decoded into a QString (UTF-16). If available, the decoding uses the Content-Type header’s charset parameter to determine the source encoding. If the encoding information is not available or not supported by QStringConverter, UTF-8 is used by default.

Calling this function consumes the data received so far. Returns a default constructed value if no new data is available, or if the decoding is not supported by QStringConverter, or if the decoding has errors (for example invalid characters).

See also

readJson() readBody() readyRead()

swap(other)
Parameters:

otherQRestReply