QNetworkReply¶
The QNetworkReply
class contains the data and headers for a request sent with QNetworkAccessManager
. More…
Synopsis¶
Functions¶
def
attribute
(code)def
error
()def
hasRawHeader
(headerName)def
header
(header)def
ignoreSslErrors
(errors)def
isFinished
()def
isRunning
()def
manager
()def
operation
()def
rawHeader
(headerName)def
rawHeaderList
()def
rawHeaderPairs
()def
readBufferSize
()def
request
()def
setAttribute
(code, value)def
setError
(errorCode, errorString)def
setFinished
(arg__1)def
setHeader
(header, value)def
setOperation
(operation)def
setRawHeader
(headerName, value)def
setRequest
(request)def
setSslConfiguration
(configuration)def
setUrl
(url)def
sslConfiguration
()def
url
()
Virtual functions¶
def
abort
()def
ignoreSslErrors
()def
ignoreSslErrorsImplementation
(arg__1)def
setReadBufferSize
(size)def
setSslConfigurationImplementation
(arg__1)def
sslConfigurationImplementation
(arg__1)
Signals¶
def
downloadProgress
(bytesReceived, bytesTotal)def
encrypted
()def
errorOccurred
(arg__1)def
finished
()def
metaDataChanged
()def
preSharedKeyAuthenticationRequired
(authenticator)def
redirectAllowed
()def
redirected
(url)def
sslErrors
(errors)def
uploadProgress
(bytesSent, bytesTotal)
Detailed Description¶
The QNetworkReply
class contains the data and meta data related to a request posted with QNetworkAccessManager
. Like QNetworkRequest
, it contains a URL and headers (both in parsed and raw form), some information about the reply’s state and the contents of the reply itself.
QNetworkReply
is a sequential-access QIODevice
, which means that once data is read from the object, it no longer kept by the device. It is therefore the application’s responsibility to keep this data if it needs to. Whenever more data is received from the network and processed, the readyRead()
signal is emitted.
The downloadProgress()
signal is also emitted when data is received, but the number of bytes contained in it may not represent the actual bytes received, if any transformation is done to the contents (for example, decompressing and removing the protocol overhead).
Even though QNetworkReply
is a QIODevice
connected to the contents of the reply, it also emits the uploadProgress()
signal, which indicates the progress of the upload for operations that have such content.
Note
Do not delete the object in the slot connected to the errorOccurred()
or finished()
signal. Use deleteLater()
.
See also
- class PySide6.QtNetwork.QNetworkReply([parent=None])¶
- Parameters
parent –
PySide6.QtCore.QObject
Creates a QNetworkReply
object with parent parent
.
You cannot directly instantiate QNetworkReply
objects. Use QNetworkAccessManager
functions to do that.
- PySide6.QtNetwork.QNetworkReply.NetworkError¶
Indicates all possible error conditions found during the processing of the request.
Constant
Description
QNetworkReply.NoError
no error condition.
Note
When the HTTP protocol returns a redirect no error will be reported. You can check if there is a redirect with the RedirectionTargetAttribute
attribute.
Constant |
Description |
---|---|
QNetworkReply.ConnectionRefusedError |
the remote server refused the connection (the server is not accepting requests) |
QNetworkReply.RemoteHostClosedError |
the remote server closed the connection prematurely, before the entire reply was received and processed |
QNetworkReply.HostNotFoundError |
the remote host name was not found (invalid hostname) |
QNetworkReply.TimeoutError |
the connection to the remote server timed out |
QNetworkReply.OperationCanceledError |
the operation was canceled via calls to |
QNetworkReply.SslHandshakeFailedError |
the SSL/TLS handshake failed and the encrypted channel could not be established. The |
QNetworkReply.TemporaryNetworkFailureError |
the connection was broken due to disconnection from the network, however the system has initiated roaming to another access point. The request should be resubmitted and will be processed as soon as the connection is re-established. |
QNetworkReply.NetworkSessionFailedError |
the connection was broken due to disconnection from the network or failure to start the network. |
QNetworkReply.BackgroundRequestNotAllowedError |
the background request is not currently allowed due to platform policy. |
QNetworkReply.TooManyRedirectsError |
while following redirects, the maximum limit was reached. The limit is by default set to 50 or as set by QNetworkRequest::setMaxRedirectsAllowed(). (This value was introduced in 5.6.) |
QNetworkReply.InsecureRedirectError |
while following redirects, the network access API detected a redirect from a encrypted protocol (https) to an unencrypted one (http). (This value was introduced in 5.6.) |
QNetworkReply.ProxyConnectionRefusedError |
the connection to the proxy server was refused (the proxy server is not accepting requests) |
QNetworkReply.ProxyConnectionClosedError |
the proxy server closed the connection prematurely, before the entire reply was received and processed |
QNetworkReply.ProxyNotFoundError |
the proxy host name was not found (invalid proxy hostname) |
QNetworkReply.ProxyTimeoutError |
the connection to the proxy timed out or the proxy did not reply in time to the request sent |
QNetworkReply.ProxyAuthenticationRequiredError |
the proxy requires authentication in order to honour the request but did not accept any credentials offered (if any) |
QNetworkReply.ContentAccessDenied |
the access to the remote content was denied (similar to HTTP error 403) |
QNetworkReply.ContentOperationNotPermittedError |
the operation requested on the remote content is not permitted |
QNetworkReply.ContentNotFoundError |
the remote content was not found at the server (similar to HTTP error 404) |
QNetworkReply.AuthenticationRequiredError |
the remote server requires authentication to serve the content but the credentials provided were not accepted (if any) |
QNetworkReply.ContentReSendError |
the request needed to be sent again, but this failed for example because the upload data could not be read a second time. |
QNetworkReply.ContentConflictError |
the request could not be completed due to a conflict with the current state of the resource. |
QNetworkReply.ContentGoneError |
the requested resource is no longer available at the server. |
QNetworkReply.InternalServerError |
the server encountered an unexpected condition which prevented it from fulfilling the request. |
QNetworkReply.OperationNotImplementedError |
the server does not support the functionality required to fulfill the request. |
QNetworkReply.ServiceUnavailableError |
the server is unable to handle the request at this time. |
QNetworkReply.ProtocolUnknownError |
the Network Access API cannot honor the request because the protocol is not known |
QNetworkReply.ProtocolInvalidOperationError |
the requested operation is invalid for this protocol |
QNetworkReply.UnknownNetworkError |
an unknown network-related error was detected |
QNetworkReply.UnknownProxyError |
an unknown proxy-related error was detected |
QNetworkReply.UnknownContentError |
an unknown error related to the remote content was detected |
QNetworkReply.ProtocolFailure |
a breakdown in protocol was detected (parsing error, invalid or unexpected responses, etc.) |
QNetworkReply.UnknownServerError |
an unknown error related to the server response was detected |
See also
- PySide6.QtNetwork.QNetworkReply.abort()¶
Aborts the operation immediately and close down any network connections still open. Uploads still in progress are also aborted.
The finished()
signal will also be emitted.
See also
close()
finished()
Returns the attribute associated with the code code
. If the attribute has not been set, it returns an invalid QVariant
(type UnknownType
).
You can expect the default values listed in Attribute
to be applied to the values returned by this function.
See also
setAttribute()
Attribute
- PySide6.QtNetwork.QNetworkReply.downloadProgress(bytesReceived, bytesTotal)¶
- Parameters
bytesReceived – int
bytesTotal – int
- PySide6.QtNetwork.QNetworkReply.encrypted()¶
- PySide6.QtNetwork.QNetworkReply.error()¶
- Return type
Returns the error that was found during the processing of this request. If no error was found, returns NoError
.
See also
- PySide6.QtNetwork.QNetworkReply.errorOccurred(arg__1)¶
- Parameters
arg__1 –
NetworkError
- PySide6.QtNetwork.QNetworkReply.finished()¶
- PySide6.QtNetwork.QNetworkReply.hasRawHeader(headerName)¶
- Parameters
headerName –
PySide6.QtCore.QByteArray
- Return type
bool
Returns true
if the raw header of name headerName
was sent by the remote server
See also
- PySide6.QtNetwork.QNetworkReply.header(header)¶
- Parameters
header –
KnownHeaders
- Return type
object
Returns the value of the known header header
, if that header was sent by the remote server. If the header was not sent, returns an invalid QVariant
.
See also
- PySide6.QtNetwork.QNetworkReply.ignoreSslErrors()¶
If this function is called, SSL errors related to network connection will be ignored, including certificate validation errors.
Warning
Be sure to always let the user inspect the errors reported by the sslErrors()
signal, and only call this method upon confirmation from the user that proceeding is ok. If there are unexpected errors, the reply should be aborted. Calling this method without inspecting the actual errors will most likely pose a security risk for your application. Use it with great care!
This function can be called from the slot connected to the sslErrors()
signal, which indicates which errors were found.
Note
If HTTP Strict Transport Security is enabled for QNetworkAccessManager
, this function has no effect.
- PySide6.QtNetwork.QNetworkReply.ignoreSslErrors(errors)
- Parameters
errors –
This is an overloaded function.
If this function is called, the SSL errors given in errors
will be ignored.
Note
Because most SSL errors are associated with a certificate, for most of them you must set the expected certificate this SSL error is related to. If, for instance, you want to issue a request to a server that uses a self-signed certificate, consider the following snippet:
cert = QSslCertificate.fromPath("server-certificate.pem")
error = QSslError(QSslError.SelfSignedCertificate, cert.at(0))
expectedSslErrors = QList()
expectedSslErrors.append(error)
reply = manager.get(QNetworkRequest(QUrl("https://server.tld/index.html")))
reply.ignoreSslErrors(expectedSslErrors)
# here connect signals etc.
Multiple calls to this function will replace the list of errors that were passed in previous calls. You can clear the list of errors you want to ignore by calling this function with an empty list.
Note
If HTTP Strict Transport Security is enabled for QNetworkAccessManager
, this function has no effect.
- PySide6.QtNetwork.QNetworkReply.ignoreSslErrorsImplementation(arg__1)¶
- Parameters
arg__1 –
This virtual method is provided to enable overriding the behavior of ignoreSslErrors()
. ignoreSslErrors()
is a public wrapper for this method. errors
contains the errors the user wishes ignored.
See also
- PySide6.QtNetwork.QNetworkReply.isFinished()¶
- Return type
bool
Returns true
when the reply has finished or was aborted.
See also
- PySide6.QtNetwork.QNetworkReply.isRunning()¶
- Return type
bool
Returns true
when the request is still processing and the reply has not finished or was aborted yet.
See also
- PySide6.QtNetwork.QNetworkReply.manager()¶
- Return type
Returns the QNetworkAccessManager
that was used to create this QNetworkReply
object. Initially, it is also the parent object.
- PySide6.QtNetwork.QNetworkReply.metaDataChanged()¶
Returns the operation that was posted for this reply.
See also
- Parameters
authenticator –
PySide6.QtNetwork.QSslPreSharedKeyAuthenticator
- PySide6.QtNetwork.QNetworkReply.rawHeader(headerName)¶
- Parameters
headerName –
PySide6.QtCore.QByteArray
- Return type
Returns the raw contents of the header headerName
as sent by the remote server. If there is no such header, returns an empty byte array, which may be indistinguishable from an empty header. Use hasRawHeader()
to verify if the server sent such header field.
See also
- PySide6.QtNetwork.QNetworkReply.rawHeaderList()¶
- Return type
Returns a list of headers fields that were sent by the remote server, in the order that they were sent. Duplicate headers are merged together and take place of the latter duplicate.
- PySide6.QtNetwork.QNetworkReply.rawHeaderPairs()¶
- Return type
Returns a list of raw header pairs.
- PySide6.QtNetwork.QNetworkReply.readBufferSize()¶
- Return type
int
Returns the size of the read buffer, in bytes.
See also
- PySide6.QtNetwork.QNetworkReply.redirectAllowed()¶
- PySide6.QtNetwork.QNetworkReply.redirected(url)¶
- Parameters
url –
PySide6.QtCore.QUrl
- PySide6.QtNetwork.QNetworkReply.request()¶
- Return type
Returns the request that was posted for this reply. In special, note that the URL for the request may be different than that of the reply.
See also
- PySide6.QtNetwork.QNetworkReply.setAttribute(code, value)¶
- Parameters
code – Attribute
value – object
Sets the attribute code
to have value value
. If code
was previously set, it will be overridden. If value
is an invalid QVariant
, the attribute will be unset.
See also
- PySide6.QtNetwork.QNetworkReply.setError(errorCode, errorString)¶
- Parameters
errorCode –
NetworkError
errorString – str
Sets the error condition to be errorCode
. The human-readable message is set with errorString
.
Calling does not emit the errorOccurred
( NetworkError
) signal.
See also
error()
errorString()
- PySide6.QtNetwork.QNetworkReply.setFinished(arg__1)¶
- Parameters
arg__1 – bool
Sets the reply as finished
.
After having this set the replies data must not change.
See also
- PySide6.QtNetwork.QNetworkReply.setHeader(header, value)¶
- Parameters
header –
KnownHeaders
value – object
Sets the known header header
to be of value value
. The corresponding raw form of the header will be set as well.
See also
Sets the associated operation for this object to be operation
. This value will be returned by operation()
.
Note
The operation should be set when this object is created and not changed again.
See also
- PySide6.QtNetwork.QNetworkReply.setRawHeader(headerName, value)¶
- Parameters
headerName –
PySide6.QtCore.QByteArray
value –
PySide6.QtCore.QByteArray
Sets the raw header headerName
to be of value value
. If headerName
was previously set, it is overridden. Multiple HTTP headers of the same name are functionally equivalent to one single header with the values concatenated, separated by commas.
If headerName
matches a known header, the value value
will be parsed and the corresponding parsed form will also be set.
See also
- PySide6.QtNetwork.QNetworkReply.setReadBufferSize(size)¶
- Parameters
size – int
Sets the size of the read buffer to be size
bytes. The read buffer is the buffer that holds data that is being downloaded off the network, before it is read with read()
. Setting the buffer size to 0 will make the buffer unlimited in size.
QNetworkReply
will try to stop reading from the network once this buffer is full (i.e., bytesAvailable()
returns size
or more), thus causing the download to throttle down as well. If the buffer is not limited in size, QNetworkReply
will try to download as fast as possible from the network.
Unlike setReadBufferSize()
, QNetworkReply
cannot guarantee precision in the read buffer size. That is, bytesAvailable()
can return more than size
.
See also
- PySide6.QtNetwork.QNetworkReply.setRequest(request)¶
- Parameters
request –
PySide6.QtNetwork.QNetworkRequest
Sets the associated request for this object to be request
. This value will be returned by request()
.
Note
The request should be set when this object is created and not changed again.
See also
- PySide6.QtNetwork.QNetworkReply.setSslConfiguration(configuration)¶
- Parameters
configuration –
PySide6.QtNetwork.QSslConfiguration
Sets the SSL configuration for the network connection associated with this request, if possible, to be that of config
.
See also
- PySide6.QtNetwork.QNetworkReply.setSslConfigurationImplementation(arg__1)¶
- Parameters
arg__1 –
PySide6.QtNetwork.QSslConfiguration
This virtual method is provided to enable overriding the behavior of setSslConfiguration()
. setSslConfiguration()
is a public wrapper for this method. If you override this method use configuration
to set the SSL configuration.
- PySide6.QtNetwork.QNetworkReply.setUrl(url)¶
- Parameters
url –
PySide6.QtCore.QUrl
Sets the URL being processed to be url
. Normally, the URL matches that of the request that was posted, but for a variety of reasons it can be different (for example, a file path being made absolute or canonical).
- PySide6.QtNetwork.QNetworkReply.sslConfiguration()¶
- Return type
Returns the SSL configuration and state associated with this reply, if SSL was used. It will contain the remote server’s certificate, its certificate chain leading to the Certificate Authority as well as the encryption ciphers in use.
The peer’s certificate and its certificate chain will be known by the time sslErrors()
is emitted, if it’s emitted.
See also
- PySide6.QtNetwork.QNetworkReply.sslConfigurationImplementation(arg__1)¶
- Parameters
arg__1 –
PySide6.QtNetwork.QSslConfiguration
This virtual method is provided to enable overriding the behavior of sslConfiguration()
. sslConfiguration()
is a public wrapper for this method. The configuration will be returned in configuration
.
- PySide6.QtNetwork.QNetworkReply.sslErrors(errors)¶
- Parameters
errors –
- PySide6.QtNetwork.QNetworkReply.uploadProgress(bytesSent, bytesTotal)¶
- Parameters
bytesSent – int
bytesTotal – int
- PySide6.QtNetwork.QNetworkReply.url()¶
- Return type
Returns the URL of the content downloaded or uploaded. Note that the URL may be different from that of the original request. If redirections were enabled in the request, then this function returns the current url that the network API is accessing, i.e the url of the resource the request got redirected to.
See also
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.